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 |
取模的方法是错的,不信自己去UVA试试。贴上代码,留给路人!#include<iostream> using namespace std; int m1[60001],m2[120001]; int array[7]; int calc(int *s,int m,int n) { int i,j,k,sum=0,rest; for(i=1;i<60001;i++) s[i]=0; s[0]=1; for(i=m;i<=n;i++) { sum+=array[i]*i; for(j=1;j<array[i];j*=2) { for(k=sum;k>=j*i;k--) if(s[k]==0&&s[k-j*i]) s[k]=1; } j=array[i]-j/2; for(k=sum;k>=j*i;k--) if(s[k]==0&&s[k-j*i]) s[k]=1; } /* for(i=0;i<=sum;i++) cout<<" "<<i<<":"<<s[i]; cout<<endl;*/ } int main() { int i,times=1,a,flag; while(cin>>array[1]) { flag=0; array[0]=0; for(i=2;i<7;i++) { cin>>array[i]; array[0]+=array[i]*i; } array[0]+=array[1]; if(array[0]==0) break; if(array[0]&0x1) {cout<<"Collection #"<<times++<<":"<<endl;cout<<"Can't be divided.\n"<<endl;continue;} array[0]/=2; calc(m1,1,3); calc(m2,4,6); for(i=0;i<=array[0];i++) if(m1[i]&&m2[array[0]-i]) { flag=1;break; } cout<<"Collection #"<<times++<<":"<<endl; if(flag) cout<<"Can be divided."<<endl; else cout<<"Can't be divided."<<endl; cout<<endl; } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator