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 ccnuzhang at 2008-03-19 10:13:11 on Problem 2184
我的递归程序  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--;
		}
	}
	cout<<endl;
	for(i=0;i<cow;i++)
		cout<<b[0][i]<<b[1][i]<<endl;
	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:
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