1 条题解

  • 0
    @ 2021-6-15 13:44:16

    C++ :

    #include<iostream>
    #include<vector>
    #include<algorithm>
    #include<cstring>
    #include<cstdio>
    #include<cmath>
    #include<cstdlib>
    #include<ctime>
    #include<queue>
    #include<set>
    #define md double
    #define LL long long
    using namespace std;
    const int N=500;
    inline int gi() {
    	int w=0;
    	bool q=1;
    	char c=getchar();
    	while ((c<'0'||c>'9') && c!='-') c=getchar();
    	if (c=='-') q=0,c=getchar();
    	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
    	return q? w:-w;
    }
    int x[N],v[N];
    int f[N][N],G[N],tot[N][N],g[N][N];LL pre[N];
    int main()
    {
    	int n=gi(),m=gi(),i,j,k,t,len,l,r,mid;LL sum;
    const int mod=1e9+7;
    	for (i=1;i<=n;i++) v[i]=x[i]=gi();
    	for (i=1;i<=n;i++) G[i]=G[i-1]+i;
    	for (i=1;i<=n;i++) for (j=i;j<=n;j++) tot[i][j]=G[i-1]+G[n-j]+G[j-i+1];
    	sort(x+1,x+1+n);len=unique(x+1,x+1+n)-x-1;
    	for (i=1;i<=n;v[i++]=l) for (l=1,r=len;l!=r;v[i]<=x[mid=(l+r)>>1]?r=mid:l=mid+1);
    	v[0]=v[n+1]=len+1;
    	for (t=1;t<=n;t++) {
    		for (l=t-1;v[l]<=v[t];l--);
    		for (r=t+1;v[r]<=v[t];r++);
    		for (i=l;i<=r;i++) for (j=i;j<=r;j++) f[i][j]=0;
    		f[++l][--r]=1;
    		for (mid=m;mid--;) {
    			for (i=l;i<=r;i++) pre[i]=0;
    			for (i=l;i<=r;i++) {
    				sum=0;
    				for (j=r;j>=i;j--) {
    					k=f[i][j];
    					f[i][j]=(1LL*k*tot[i][j]+sum+pre[j])%mod;
    					sum+=1LL*k*(n-j);
    					pre[j]+=1LL*k*(i-1);
    				}
    			}
    		}
    		for (i=l;i<=r;i++)
    			for (j=r,sum=0;j>=i;j--) {
    				sum+=f[i][j];
    				g[j][v[t]]=(g[j][v[t]]+sum)%mod;
    			}
    	}
    	for (i=1;i<=n;i++) {
    		sum=0;k=0;
    		for (j=1;j<=len;j++)
    			if (g[i][j])
    				sum+=1LL*x[j]*(g[i][j]-k),k=g[i][j];
    		printf("%d ",int((sum%mod+mod)%mod));
    	}
    	return 0;
    }
    
    • 1

    信息

    ID
    958
    时间
    4000ms
    内存
    256MiB
    难度
    10
    标签
    递交数
    1
    已通过
    1
    上传者