标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 22808 Accepted Submission(s): 6444
1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 #include<algorithm> 5 #define ll __int64 6 using namespace std; 7 int n[10]; 8 int m; 9 int jishu; 10 int size[60005]; 11 int value[60005]; 12 int coun=1; 13 int f[60005]; 14 void slove(int q) 15 { 16 coun=1; 17 for(int i=1;i<=q;i++) 18 { 19 int c=n[i],v=i; 20 for (int k=1; k<=c; k<<=1) 21 { 22 value[coun] = k*v; 23 size[coun++] = k*v; 24 c -= k; 25 } 26 if (c > 0) 27 { 28 value[coun] = c*v; 29 size[coun++] = c*v; 30 } 31 } 32 } 33 int main() 34 { jishu=0; 35 while(scanf("%d %d %d %d %d %d",&n[1],&n[2],&n[3],&n[4],&n[5],&n[6])!=EOF) 36 { 37 if(n[1]==0&&n[2]==0&&n[3]==0&&n[4]==0&&n[5]==0&&n[6]==0) 38 break; 39 memset(f,0,sizeof(f)); 40 memset(size,0,sizeof(size)); 41 memset(value,0,sizeof(value)); 42 m=n[1]+n[2]*2+n[3]*3+n[4]*4+n[5]*5+n[6]*6; 43 if(m%2) 44 { 45 printf("Collection #%d:\nCan‘t be divided.\n\n",++jishu); 46 } 47 else 48 { 49 slove(6); 50 m=m/2; 51 for(int i=1;i<=coun-1;i++) 52 for(int k=m;k>=value[i];k--) 53 { 54 f[k]=max(f[k],f[k-size[i]]+value[i]); 55 } 56 if(f[m]==m) 57 printf("Collection #%d:\nCan be divided.\n\n",++jishu); 58 else 59 printf("Collection #%d:\nCan‘t be divided.\n\n",++jishu); 60 61 } 62 63 } 64 return 0; 65 }
标签:
原文地址:http://www.cnblogs.com/hsd-/p/5460302.html