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<cstdio> #include<cstdlib> int stick[64]; bool flag[64]; int n; int cmp(const void *a,const void *b) { return *(int *)b-*(int *)a; } bool isok(int sum,int i,int row) { if(row==0) return false; flag[i]=true; if(sum-stick[i]==0) return true; if(sum-stick[i]>0) { for(int j=i+1;j<n;j++) if(!flag[j]&&isok(sum-stick[i],j,row-1)) return true; } flag[i]=false; return false; } int main() { int i,max,sum,row; while(scanf("%d",&n),n!=0) { max=0; sum=0; for(i=0;i<n;i++) { scanf("%d",stick+i); flag[i]=false; if(stick[i]>max) max=stick[i]; sum+=stick[i]; } qsort(stick,n,sizeof(int),cmp); while(1) { if(sum%max==0) { row=max; for(i=0;i<n;i++) if(!flag[i]&&!isok(max,i,row)) break; if(i==n) break; } max++; for(i=0;i<n;i++) flag[i]=false; } printf("%d\n",max); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator