标签:des style blog http color os io strong
Description
Input
Output
Sample Input
1 0 1 2 0 0 1 0 0 0 1 1 0 0 0 0 0 0
Sample Output
Collection #1: Can‘t be divided. Collection #2: Can be divided.
1 #include<cstdio> 2 #include<string.h> 3 #include<math.h> 4 using namespace std; 5 int dp[100000]; 6 int main() 7 { 8 int a[11]; 9 int t=1; 10 int cnt; 11 while(scanf("%d %d %d %d %d %d",&a[1],&a[2],&a[3],&a[4],&a[5],&a[6])!=EOF) 12 { 13 if(a[1]+a[2]+a[3]+a[4]+a[5]+a[6]==0) break; 14 int sum,x; 15 sum=a[1]*1+a[2]*2+a[3]*3+a[4]*4+a[5]*5+a[6]*6; 16 printf("Collection #%d:\n",t); 17 t++; 18 if(sum%2) 19 { 20 printf("Can‘t be divided.\n\n"); 21 continue; 22 } 23 x=sum/2; 24 memset(dp,0,sizeof(dp)); 25 dp[0]=1; 26 for(int i=1;i<=6;i++) 27 { 28 if(!a[i]) 29 continue; 30 for(int j=1;j<=a[i];j*=2) 31 { 32 cnt=j*i; 33 for(int k=x;k>=cnt;k--) 34 { 35 if(dp[k-cnt]) 36 dp[k]=1; 37 } 38 a[i]-=j; 39 } 40 cnt=a[i]*i; 41 if(cnt) 42 { 43 for(int k=x;k>=cnt;k--) 44 { 45 if(dp[k-cnt]) 46 dp[k]=1; 47 } 48 } 49 } 50 if(dp[x]) 51 printf("Can be divided.\n"); 52 else printf("Can‘t be divided.\n"); 53 printf("\n"); 54 } 55 return 0; 56 }
标签:des style blog http color os io strong
原文地址:http://www.cnblogs.com/angledamon/p/3922495.html