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 |
测试了discuss里所有数据都对,可就是wa,那为高手帮忙看看int a[65],u[65],b,o,d[65]; int Find(int n,int s) {int t,pre=-1; if(s==0) return(o=1); else for(t=n;t<b&&o!=1;t++) { if(u[t]!=1&&a[t]<=s&&a[t]!=pre) {u[t]=1; Find(t+1,s-a[t]); if(o==0) {u[t]=0;pre=a[t];} } }} main() {int c,i,j,k,sum; scanf("%d",&b); while(b!=0) {o=0; sum=0; for(i=0;i<b;i++) { scanf("%d",&c); if(c<=50) {if(i==0) a[i]=c; else {for(j=i-1;j>=0;j--) if(c<=a[j]) break; for(k=i-1;k>j;k--) a[k+1]=a[k]; a[j+1]=c;} sum=sum+c;}} for(i=a[0];i<=sum&&o!=1;i++) {if(sum%i==0) {o=1; for(j=0;j<b;j++) u[j]=0; for(j=0;j<(sum/i)&&o==1;j++) {o=0; for(k=0;k<b;k++) {if(u[k]==0) break;} u[k]=1; d[j]=k; Find(k+1,i-a[k]); if(o==0) {for(k=0;k<b;k++) u[k]=0; o=1; for(k=j;k>=0&&o==1;k--) {o=0; u[k]=1; Find(d[k]+1,i-a[d[k]]);} }}}} printf("%d\n",i-1); scanf("%d",&b);} } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator