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 901001 at 2010-03-05 12:13:48 on Problem 1321
下面是本人代码,大家看看有什么数据不能过去。
#include<iostream>
using namespace std;
char s[9][9];
int  flag[9][9];
bool hang[9],lie[9];
int n,k,sum;
void dfs(int a,int b,int k)
{
	if(k==0)
	{
		sum++;
		return ;
	}
	if(n-a<k)
		return ;
	if(b>=n)
		dfs(a+1,0,k);
	else if(a>=n)
		return ;
	else
	{
	   if(flag[a][b]==0&&hang[a]==false&&lie[b]==false)
	   {
		   hang[a]=true;
		  lie[b]=true;
		  
		  dfs(a+1,0,k-1);
		  hang[a]=false;
		  lie[b]=false;
          

	   }
	   dfs(a,b+1,k);
	}
}
int main()
{
	
	while(scanf("%d%d",&n,&k)!=EOF)
	{
		memset(hang,0,sizeof(hang));
		memset(lie,0,sizeof(lie));
		sum=0;
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<n;j++)
			{
				cin>>s[i][j];
				if(s[i][j]=='#')
					flag[i][j]=0;
				else if(s[i][j]=='.')
					flag[i][j]=1;
			}
		}
		if(k==0)
			printf("0\n");
		else
		{
		dfs(0,0,k);
		printf("%d\n",sum);
		}
	}
	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