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
北京大学《ACM/ICPC大学生程序设计竞赛训练》暑期课面向全球招生!

求大牛们帮帮小弟看看这代码为啥一直wa 谢啦 或者给一些数据也行 多谢啦

Posted by suda1427405048 at 2015-04-02 23:46:50 on Problem 1321
#include <stdio.h>
#include <algorithm>

char a[10][10];  
int vis[9];               //为0时则没走过  为1时  表示走过

int m;
void dfs(int k,int n,int t,int nm);

int main()
{
	int n,k,i,j,t;
	while(scanf("%d%d",&n,&k)!=EOF)
	{
		if(n==-1&&k==-1)
			return 0;

		getchar();
		for(i=1;i<=n;i++)
		{
			for(j=1;j<=n;j++)
			{
				scanf("%c",&a[i][j]);
				getchar();
			}
		}
		memset(vis,0,9*sizeof(int));
		t=1;
		m=0;
		dfs(k,n,t,1);
		printf("%d\n",m);
	}
}

void dfs(int k,int n,int t,int nm)
{
	int i,j;
	if(t==k+1)           //t代表的是该搜索的第t个数
	{
		m++;
		return ;
	}
	else
	{
		for(i=nm;i<=n;i++)           //nm表示行数
		{
			for(j=1;j<=n;j++)
			{
				if(a[i][j]=='#'&&vis[j]!=1)
				{
					vis[j]=1;
					dfs(k,n,t+1,i+1);
					vis[j]=0;
				}
			}
		}
		return ;
	}
}

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