标签:des style blog http color java os io
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 16909 Accepted Submission(s): 4729
1 #include <cstdio> 2 #include <cstring> 3 #include <vector> 4 #include <algorithm> 5 #include <iostream> 6 using namespace std; 7 8 int dp[100000]; 9 int v[30]; 10 11 main() 12 { 13 int n, i, j, k, sum, kase=1; 14 int a[7]; 15 while(scanf("%d %d %d %d %d %d",&a[1],&a[2],&a[3],&a[4],&a[5],&a[6])==6&&(a[1]+a[2]+a[3]+a[4]+a[5]+a[6])){ 16 n=0; 17 memset(dp,0,sizeof(dp)); 18 printf("Collection #%d:\n",kase++); 19 sum=a[1]+a[2]*2+a[3]*3+a[4]*4+a[5]*5+a[6]*6; 20 if(sum&1){ 21 printf("Can‘t be divided.\n\n");continue; 22 } 23 for(i=1;i<=6;i++){ 24 n=0; 25 for(j=1;j<=a[i];j<<=1){ 26 v[n++]=j; 27 a[i]-=j; 28 } 29 if(a[i]>0){ 30 v[n++]=a[i]; 31 } 32 for(j=0;j<n;j++){ 33 for(k=sum/2;k>=v[j]*i;k--) 34 dp[k]=max(dp[k],dp[k-v[j]*i]+v[j]*i); 35 } 36 } 37 38 if(dp[sum/2]==sum/2){ 39 printf("Can be divided.\n\n"); 40 } 41 else printf("Can‘t be divided.\n\n"); 42 } 43 }
HDU 1059 多重背包+二进制优化,布布扣,bubuko.com
标签:des style blog http color java os io
原文地址:http://www.cnblogs.com/qq1012662902/p/3911229.html