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

各种wa 求掐

Posted by anlan at 2010-04-25 18:29:00 on Problem 1770
#include<iostream>
#include<cstring>
#include<algorithm>

using namespace std;

int p[201],used0[201],used1[201],n;
bool g[201][201];

int maxl(int x,int y)
{
	return x>y?x:y;
}

int dfs1(int x);
int dfs0(int x);

int dfs0(int x)
{
	if(used0[x]!=-1)return used0[x];
	int i,tmp;
	tmp=0;
	for(i=0;i<n;i++)
	{
		if(g[x][i]==1)
		{
			tmp+=dfs1(i);
		}
	}
	tmp+=p[x];
	used0[x]=tmp;
	return tmp;
}

int dfs1(int x)
{
	if(used1[x]!=-1)return used1[x];
	int i,tmp;
	tmp=0;
	for(i=0;i<n;i++)
	{
		if(g[x][i]==1)
		{
			tmp+=maxl(dfs0(i),dfs1(i));
		}
	}
	used1[x]=tmp;
	return tmp;
}

int main()
{
	int i,j,k,t,m,used[201];
	while(cin>>n>>m)
	{
		if(n==0&&m==0)break;
		for(i=0;i<n;i++)
		{
			cin>>p[i];
		}
		memset(g,0,sizeof(g));
		memset(used0,-1,sizeof(used0));
		memset(used1,-1,sizeof(used1));
		memset(used,0,sizeof(used));
		for(i=0;i<m;i++)
		{
			cin>>t;
			for(k=0;k<n;k++)
			{
				for(j=k-1;j>=0;j--)
				{
					if(p[k]-p[j]==t)
					{
						g[j][k]=1;
						used[k]=1;
					}
				}
			}
		}
		k=0;
		for(i=0;i<n;i++)
		{
			if(used[i]==0)k+=maxl(dfs0(i),dfs1(i));
		}
		cout<<k<<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