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

回溯 函数递归 不模拟 都能0s呢……只是不小心贡献了一个RE,怎么前辈讨论消减时间这么激烈??

Posted by 15914304086 at 2012-04-01 20:44:19 on Problem 1321
#include <iostream>
using namespace std;

char hl[9],maze[9][9];
int n,ii;

void search(const int k,const int bian)
{
	int i,j;
	for (i=bian-1;i>k-2;i--)
	{
		for (j=0;j<n;j++)
			if (maze[i][j]=='#' && hl[j]==0)
				if (i && k>1)
				{
					hl[j]=1;
					search(k-1,i);
					hl[j]=0;
				}
				else
					ii++;
	}
}

int main()
{
	int k,i;
	while(1)
	{
		cin>>n>>k;
		if (n==-1)
			break;
		else
		{
			memset(hl,0,sizeof(hl));
			for (i=0;i<n;i++)
				scanf("%s",maze[i]);
			ii=0;
			search(k,n);
			cout<<ii<<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