Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
代码是这样的:#include <iostream> using namespace std; int n[7]; bool flag; void dfs(int des) { if(des==0) { flag=true; return; } for(int i=6;i>0;i--) { if(des>=i && n[i]>0) { n[i]--; dfs(des-i); if(flag) return; } } } int main() { int count=1; while(cin >> n[0] >> n[1] >> n[2] >> n[3] >> n[4] >> n[5]) { int sum=0; for(int i=1;i<=6;i++) sum+=(i+1)*n[i]; if(sum==0) break; if(sum%2==1) { cout << "Collection #" << count << ":\n" << "Can't be divided.\n\n"; count++; } else { int des=sum/2; flag=false; dfs(des); if(flag) cout << "Collection #" << count << ":\n" << "Can be divided.\n\n"; else cout << "Collection #" << count << ":\n" << "Can't be divided.\n\n"; count++; } } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator