标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 19117 Accepted Submission(s): 5363
#include<iostream> #include<cstring> #include<cmath> #include<string> #include<cstdlib> #include<algorithm> #include<cstdio> using namespace std; int f[7],w[100010],dp[100010]; int main() { int cnt=0; while(scanf("%d%d%d%d%d%d",&f[1],&f[2],&f[3],&f[4],&f[5],&f[6])!=EOF) { if(f[1]+f[2]+f[3]+f[4]+f[5]+f[6]==0) continue; memset(dp,0,sizeof(dp)); int k=0,sum=0,v; for(int i=1;i<=6;i++) { sum+=f[i]*i; for(int j=1;j<=f[i];j<<=1) { w[++k]=j*i; f[i]-=j; } if(f[i]>0) { w[++k]=f[i]*i; } } v=sum/2; for(int i=1;i<=k;i++) { for(int j=v;j>=w[i];j--) dp[j]=max(dp[j],dp[j-w[i]]+w[i]); } printf("Collection #%d:\n",++cnt); if(dp[v]==sum-v) { printf("Can be divided.\n"); } else printf("Can‘t be divided.\n"); printf("\n"); } return 0; }
标签:
原文地址:http://www.cnblogs.com/a972290869/p/4420531.html