NC214901. Fountains
描述
输入描述
The first line contains an integer . The second line contains space separated integers .
输出描述
The output contains integers in their own lines, the expectations when multiplied by . It can be shown that the results are always integers.
示例1
输入:
1 1
输出:
0
说明:
For the first test case, we only need to consider the case . We can only choose . Then the expected loss is and the result is .示例2
输入:
2 13 24
输出:
26 13 0
示例3
输入:
3 6 4 7
输出:
33 21 12 8 4 0
说明:
For the third test case, consider the case when . We choose , and . The expected loss is 2. And the result is .C++(clang++11) 解法, 执行用时: 1579ms, 内存消耗: 101624K, 提交时间: 2021-02-07 09:45:45
#include<bits/stdc++.h> #define ll long long #define pb push_back using namespace std; int n,num; ll sum,s[11],ans[89]; struct P{ll v;int l,r;}a[89]; map<vector<int>,ll>cur,pre; vector<int>b; int main(){ scanf("%d",&n); for(int i=1;i<=n;++i)scanf("%lld",&s[i]),s[i]+=s[i-1]; for(int i=1;i<=n;++i) for(int j=i;j<=n;++j){ a[++num]=P{s[j]-s[i-1],i,j}; sum+=s[j]-s[i-1]; } sort(a+1,a+num+1,[&](P x1,P x2){return x1.v>x2.v;}); for(int i=0;i<n;++i)b.pb(n);b.pb(0); cur[b]=0; for(int x=1;x<=num;++x){ int l=a[x].l,r=a[x].r;ll v=a[x].v; pre=cur; for(auto o:pre){ auto b=o.first;ll nv=o.second; for(int i=0;i<l;++i){ if(b[i]>=r)nv+=(b[i]-r+1)*v,b[i]=r-1; } b[n]++; cur[b]=max(cur[b],nv); ans[b[n]]=max(ans[b[n]],nv); } } for(int i=1;i<=(n+1)*n/2;++i)printf("%lld\n",sum-ans[i]); return 0; }