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 |
wa了好多次。。。。。。。。。。。。。。然后莫名奇妙的过了#include<stdio.h> #include<string.h> #include<iostream> #include<queue> using namespace std; bool f[100][50000]; int main() { int n[7]; int mol[7]={0,60*30,30*20,20*15,15*12,12*10,10}; for(int t=1;;t++) { int k=0; for(int i=1;i<7;i++) {scanf("%d",&n[i]);if(n[i])k=1;} if(!k)return 0; printf("Collection #%d:\n",t); int sum=0; for(int i=1;i<7;i++) { n[i]%=mol[i]; sum+=i*n[i]; } if(sum%2){printf("Can't be divided.\n\n");continue;} sum/=2; queue <int> s; for(int i=1;i<7;i++) { if(!n[i])continue; int j; for(j=1;2*j-1<n[i];j*=2) { s.push(j*i); //printf("%d\n",i*j); } s.push((n[i]-j+1)*i); //printf("%d\n",(n[i]-j+1)*i); } memset(f,false,sizeof(f)); f[0][0]=true; int x; bool re=false; for(int i=1;!s.empty();i++,s.pop()) { x=s.front(); for(int j=0;x<=sum&&j<=sum-x;j++) { if(f[i-1][j]) {f[i][j]=true;f[i][j+x]=true;} if(f[i][sum]){re=true; goto inx;} } } inx: if(re)printf("Can be divided.\n\n"); else printf("Can't be divided.\n\n"); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator