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了,高人指点一下啊帮忙看一下吧,讨论的几组数据都过了。给几组数据或者发个ac的也好啊,谢谢了。 #include<iostream> #include<cmath> #include<algorithm> #include<functional> using namespace std; bool s(int len,int *stick,int n); bool sf(int len,int *stick,int n) { int k; int t=0; for(k=0;k<n;k++) { if(len<0) return 0; if(stick[k]==0) continue; if(len==stick[k]) { stick[k]=0; continue; } t=stick[k]; stick[k]=0; if(s(len-t,stick+1,n-1)==0) return 0; } if(k==n) return 1; return 0; } bool s(int len,int *stick,int n) { int i; if(len<0) return 0; for(i=0;i<n;i++) { if(stick[i]==len) { stick[i]=0; return 1; } if(stick[i]==0) continue; int t=stick[i]; stick[i]=0; if(s(len-t,stick,n)==0) stick[i]=t; else return 1; } return 0; } int main() { while(1) { int amount; int *stick; int *save; int sum=0; int max=0; int i; cin>>amount; if(amount==0) break; stick=new int[amount]; save=new int[amount]; for(i=0;i<amount;i++) { cin>>stick[i]; if(stick[i]>50) { i--; amount--; continue; } save[i]=stick[i]; sum+=stick[i]; } sort(stick,stick+amount,greater<int>()); for(i=sqrt(sum);i>=2;i--) { if(sum%i==0) if(sum/i>=stick[0]) if(sf(sum/i,stick,amount)) { cout<<(sum/i)<<endl; break; } else copy(save,save+amount,stick); } if(i==1) cout<<sum<<endl; } return 1; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator