Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

这代码,搜的有问题啊??

Posted by dynamic_study at 2009-07-19 09:21:00 on Problem 2184 and last updated at 2009-07-19 09:22:29
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator