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> using namespace std; const int N=100; int b[2][N]; int cow,TS,TF,TA; bool use[N]; bool DFS(int seat,int nTA,int nTS,int nTF) { int i; if(nTS>0&&nTF>0&&nTA>TA) TA=nTA; if(nTA==0) { for(i=0;i<cow;i++) if(!use[i]) { use[i]=true; DFS(i,nTA+b[0][i]+b[1][i],nTS+b[0][i],nTF+b[1][i]); use[i]=false; } } else { for(i=seat;i<cow;i++) if(!use[i]&&nTA+b[0][i]+b[1][i]>nTA) { use[i]=true; DFS(i,nTA+b[0][i]+b[1][i],nTS+b[0][i],nTF+b[1][i]); use[i]=false; } } return false; } int main() { int i; cin>>cow; memset(use,false,sizeof(use)); for(i=0;i<cow;i++) { cin>>b[0][i]>>b[1][i]; if(b[0][i]<=0&&b[1][i]<=0) { i--; cow--; } } TS=0,TF=0,TA=0; DFS(0,0,0,0); if(TA) cout<<TA<<endl; else cout<<"0"<<endl; return 0; } 这是我的... Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator