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 huxinjie800 at 2010-04-02 23:24:37 on Problem 1659 and last updated at 2010-04-02 23:25:08
#include <iostream>
using namespace std;
int num[15];
int map[15][15];
int cc[15];
int n,ff;
bool judge()
{
	for(int i=0;i<n;i++)
	{
		if(cc[i]!=num[i])return 0;
	}
	return 1;
}
void dfs(int x,int y)
{
	if(judge())
	{
		ff=1;		
	}
	if(y>=n)return ;
	if(ff==0)
	{
		if(map[x][y]==0&&cc[x]<num[x]&&cc[y]<num[y])
		{
			cc[x]++;
			cc[y]++;
			map[x][y]=1;
			map[y][x]=1;
		}
		y++;
		if(y>=n){x++;y=x+1;}
		if(x>=n)return ;
		dfs(x,y);
	}
	if(ff==0)
	{
		if(map[x][y]==1)
		{
			cc[x]--;
			cc[y]--;
			map[x][y]=0;
			map[y][x]=0;
		}
	}
	return ;
}
int main ()
{
	int T;
	scanf("%d",&T);
	while(T--)
	{
		scanf("%d",&n);
		for(int i=0;i<n;i++)scanf("%d",num+i);
		memset(map,0,sizeof(map));
		memset(cc,0,sizeof(cc));
		ff=0;
		dfs(0,1);
		if(ff==0)printf("NO\n\n");
		else
		{
			printf("YES\n");
			for(int i=0;i<n;i++)
			{
				for(int j=0;j<n;j++)printf("%d ",map[i][j]);
				printf("\n");
			}
			printf("\n");
		}
	}
	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