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 |
高手们给看看,为什么TLE了??? 谢谢!!!#include <iostream> #include <fstream> using namespace std; int n[10]; int allnum[10000]; int mark[100]; int an; bool findn(int cur){ if(cur==0)return true; else{ for(int i=2;i<an;i++){ if(mark[i]==0&&allnum[i]<=cur){ mark[i]=1; int sum=cur-allnum[i]; if(findn(sum))return true; mark[i]=0; } } } return false; } bool compute(){ memset(allnum,0,sizeof(allnum)); an=1; int sum=0; for(int j=1;j<=6;j++){ for(int k=1;k<=n[j];k++){ allnum[an++]=j; sum+=j; } } if(sum%2==1)return false; int half=sum/2; memset(mark,0,sizeof(mark)); mark[1]=1; return findn(half-allnum[1]); } bool bk(){ for(int i=1;i<=6;i++){ if(n[i]!=0)return false; } return true; } void main(){ int testcase=1; while(1){ for(int i=1;i<=6;i++){ cin>>n[i]; n[i]%=30; } if(bk())break; cout<<"Collection #"<<testcase++<<":"<<endl; if(compute())cout<<"Can be divided."<<endl; else cout<<"Can't be divided."<<endl; } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator