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 |
这代码,搜的有问题啊??#include<iostream> using namespace std; int si[1000],fi[1000],sumn[1000],ans=-999999,n; void dfs(int p,int ssum,int fsum,int sum) { if(p>n) { if(sum>ans) ans=sum; return ; } if(ssum+si[p]>=0&&fsum+fi[p]>=0)//左子树 dfs(p+1,ssum+si[p],fsum+fi[p],sum+sumn[p]); dfs(p+1,ssum,fsum,sum);//右子树 } int main() { int i; cin>>n; for(i=1;i<=n;i++) { cin>>si[i]>>fi[i]; sumn[i]=si[i]+fi[i]; } dfs(1,0,0,0); cout<<ans<<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