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 |
有哪位大神可以帮我看一下1014题我错在哪里吗???orz#include<stdio.h> int s[20000]={0}; int dfs(int now,int x) { int i; if(now==0) return 1; if(now&&!x) return 0; for(i=x-1;i>=0;i--) { if(now>=s[i]) { if(dfs(now-s[i],i)) return 1; else { while(i&&s[i]==s[i-1]) i--; if(i==0) return 0; } } } //return 0; } int main() { int a[6]; int k=0,i,sum,j,n; while(scanf("%d %d %d %d %d %d",&a[0],&a[1],&a[2],&a[3],&a[4],&a[5]),a[0]+a[1]+a[2]+a[3]+a[4]+a[5]) { k++; sum=0;j=0;n=0; for(i=0;i<6;i++) { sum+=(i+1)*a[i]; n+=a[i]; } if(sum%2==1) { printf("Collection #%d:\nCan't be divided.\n\n",k); } else { for(i=0;i<6;i++) { while(a[i]) { s[j++]=i+1; a[i]--; } } if(dfs(sum/2,n)) printf("Collection #%d:\nCan be divided.\n\n",k); else printf("Collection #%d:\nCan't be divided.\n\n",k); } } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator