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 |
打DOTA的帮忙看一下为什么WA啊,过全部数据啊/*【推荐测试数据】 9 15 3 2 11 4 1 8 8 8 6 6 2 2 4 8 8 5 1 1 1 1 1 2 1 1 4 2 2 9 9 3 1 2 3 64 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 43 42 42 41 10 4 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 7 49 48 47 46 45 44 43 7 3 4 5 5 5 5 13 7 2 7 7 7 7 10 20 6 1 2 3 11 11 20 7 63 2 44 12 60 35 60 9 5 2 1 5 2 1 5 2 1 4 1 2 3 4 64 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 33 33 31 31 64 40 40 30 35 35 26 15 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 43 42 42 41 10 4 40 40 40 40 40 40 40 40 40 40 40 40 40 40 25 39 46 40 10 4 40 40 37 18 17 16 15 40 40 40 40 40 40 40 40 0 */ #include <iostream> using namespace std; bool used[78]={0}; bool used1[65]={0}; int a[75]={0}; int n; int sum=0; //bool flag=0; int cmp(const void* a,const void* b) { return *(int*)b-*(int*)a; } bool dfs(int len,int le,int k) //k表示当前已填充木棒个数,n表示还需填充长度,len表示当前可能的长度 { if(le==0) { // cout<<"here return"<<endl; if(k==0) { return 1; } else { for(int i=1;i<=n;i++) { used[i]=used1[i]; used1[i]=0; } return dfs(len,len,k-1); } } else { for(int j=1;j<=n;j++) { if(!used1[j] && !used[j] && a[j]<=le) { //cout<<"loop"<<j<<endl; used1[j]=1; if(dfs(len,le-a[j],k)) return 1; used1[j]=0; } } } return 0; } int main() { while(cin>>n) { if(n==0) break; for(int i=1;i<=n;i++) { cin>>a[i]; sum+=a[i]; } qsort(a+1,n,sizeof(int),cmp); for(int k=a[1];k<=sum;k++) { if(sum%k==0) { if(dfs(k,k,sum/k)) { cout<<k<<endl; break; } } } memset(a,0,sizeof(a)); memset(used,0,sizeof(used)); memset(used1,0,sizeof(used)); sum=0; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator