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> #include <cstdlib> #include <cstdio> #include <cmath> #include <string> #include <cstring> using namespace std; const int M=20010; int a[M]; int f[M*10]={0}; int main() { int n,m; int ans=0; int iii=0; while(true) { memset(f,0,sizeof(f)); iii++; m=0;ans=0; for(int i=1; i<=6; i++) { cin>>n; ans=ans+n*i; if(n!=0) while(n--) { a[m]=i; m++; } } if(m==0) break; if(ans%2==1) { printf("Collection #%d:\nCan't be divided.\n\n",iii); continue; } m--; ans=ans/2; f[0]=1; for(int i=1; i<=m; i++) { for(int j=ans; j>=a[i]; j--) f[j]=f[j]+f[j-a[i]]; } if(f[ans]>0) printf("Collection #%d:\nCan be divided.\n\n",iii); else printf("Collection #%d:\nCan't be divided.\n\n",iii); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator