标签:strong col std 延伸 转移 min pre can 不同
1 #include <cstdio> 2 #include <iostream> 3 #include <cstring> 4 #include <algorithm> 5 #define ll long long 6 using namespace std; 7 const ll N=1e3+10,inf=0x7fffffff; 8 ll f[3][N][N],a[N],n,l,r; 9 int main() 10 { 11 freopen("b.in","r",stdin),freopen("b.out","w",stdout),scanf("%lld",&n); 12 for (ll i=1;i<=n;i++) scanf("%lld",&a[i]); 13 for (int i=0;i<=n;i++) for (int j=0;j<=n;j++) f[0][i][j]=inf; 14 sort(a+1,a+n+1),f[0][1][0]=0; 15 for (ll i=2;i<=n;i++) a[i]+=a[i-1]; 16 for (ll i=0;i<n;i++) 17 { 18 l=i&1,r=l^1; 19 for (ll j=0;j<=n-i;j++) for (ll k=0;k<=n-i-j;k++) f[r][j][k]=inf; 20 for (ll j=0;j<=n-i;j++) 21 for (ll k=0;k<=n-i-j;k++) 22 if (f[l][j][k]!=inf) 23 { 24 if (j) f[r][j-1][k]=min(f[r][j-1][k],f[l][j][k]); 25 if (j+k) f[l][j+k][j]=min(f[l][j+k][j],f[l][j][k]+a[n-i]); 26 } 27 } 28 printf("%lld",f[r][0][0]); 29 }
标签:strong col std 延伸 转移 min pre can 不同
原文地址:https://www.cnblogs.com/Comfortable/p/10321783.html