标签:blank 技术 last cas cst gets mit pos display
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 69575 | Accepted: 18138 |
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.
Source
#include<cstdio> #include<cstring> using namespace std; int a[7],sum_value=0,ci[7][20001],now=0; bool dp[7][120000]; bool Check_Answer() { memset(dp,false,sizeof(dp)); dp[0][0]=true; for(int i=1;i<=6;i++) { for(int j=0;j<=sum_value;j++) { if(dp[i][sum_value]) return true; if(dp[i-1][j]) { for(int v=0;v<=a[i];v++) dp[i][j+ci[i][v]]=true; } } } if(dp[6][sum_value]) return true; else return false; } int main() { bool if_break; while(1) { if_break=true,sum_value=0,now++; for(int i=1;i<=6;i++) { scanf("%d",&a[i]); if(a[i]) if_break=false; sum_value+=a[i]*i; for(int j=1;j<=a[i];j++) ci[i][j]=i*j; } if(if_break) break; if(sum_value%2) { printf("Collection #%d:\nCan‘t be divided.\n\n",now); continue; } sum_value/=2; if(Check_Answer()) printf("Collection #%d:\nCan be divided.\n\n",now); else printf("Collection #%d:\nCan‘t be divided.\n\n",now); } return 0; }
另附我的一个失败代码:
#include<cstdio> #include<cstring> using namespace std; int a[7],sum_value,num,ci[20001],flag; bool dp[70000]; int main() { int now=0; while(1) { now++; memset(dp,false,sizeof(dp)); sum_value=0,num=0,flag=1; bool if_break=true; for(int i=1;i<=6;i++) { scanf("%d",&a[i]); sum_value+=a[i]*i,num+=a[i]; if(a[i]!=0) { if_break=false; for(int j=flag;j<flag+a[i];j++) ci[j]=i; flag+=a[i]; } } if(if_break) break; if(sum_value%2) { printf("Collection #%d:\nCan‘t be divided.\n\n",now); continue; } sum_value/=2; int max_now=0; dp[0]=true; for(int i=1;i<=num;i++) { int max_now_=max_now; for(int j=0;j<=max_now;j++) { if(dp[j]) { dp[j+ci[i]]=true; if(j+ci[i]==sum_value) { printf("Collection #%d:\nCan be divided.\n\n",now); if_break=true; break; } if(j+ci[i]>max_now_&&j+ci[i]<=sum_value) max_now_=j+ci[i]; } } max_now=max_now_; if(if_break) break; } if(if_break) continue; printf("Collection #%d:\nCan‘t be divided.\n\n",now); } return 0; }
标签:blank 技术 last cas cst gets mit pos display
原文地址:http://www.cnblogs.com/IUUUUUUUskyyy/p/6209273.html