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 zpdlut at 2010-08-16 11:14:29 on Problem 1129
#include<iostream>
#define MAX 27
using namespace std;
int set[MAX][MAX];
int result[MAX];
int lines;
int m;
void dfs(int x)
{
	if(x == lines)
	{
		int get=0;
		for(int i=0;i<lines;i++)
		{
			if(result[i]>get)
				get = result[i];
		}
		if(get<m)
			m = get;
		return;
	}
	int j;
	for(int i=1;i<=4;i++)
	{
		for(j=0;j<lines;j++)
		{
			if(set[x][j]==1&&result[j]==i)
				break;
		}
		if(j==lines){
			result[x] = i;
			dfs(x+1);
		}
	}
	

}
int main()
{

	char ch[27];
	while(cin>>lines&&lines)
	{
		int step = 1;
		m = 5;
		memset(set,0,sizeof(set));
		memset(result,0,sizeof(result));
		for(int i=0;i<lines;i++)
		{
			
			cin>>ch;
			for(int j=2;ch[j]!='\0';j++)
			set[i][ch[j]-'A']=1;
		}
		result[0] = 1;
		dfs(1);
		
		if(m==1)
			cout<<m<<" channel needed."<<endl;
		else
			cout<<m<<" channels needed."<<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