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

为什么大家爆搜也就16ms,我爆搜要47ms,这是什么情况,有人能分析下么,附代码

Posted by scuwf at 2011-11-01 17:26:30 on Problem 1321
#include<stdio.h>
#define MAX 9
int hashrow[MAX];
int hashcol[MAX];
char map[MAX][MAX];
int n,k,count;
void DFS(int pre)
{
	int i,j;
	if(k==0)
	{
		count++;
		return;
	}
	for(i=pre+1;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
			if(map[i][j]=='#' && hashrow[i]==0 && hashcol[j]==0)
			{
				hashrow[i]=hashcol[j]=1;
				k--;
				DFS(i);
				k++;
				hashrow[i]=hashcol[j]=0;
			}
		}
	}
}
int main(void)
{
	int i;
	while(scanf("%d%d",&n,&k) && n!=-1)
	{
		count=0;
		for(i=0;i<n;i++) scanf("%s",map[i]);
		DFS(-1);
		printf("%d\n",count);
	}
	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