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

谁给帮帮忙,看看代码哪里错了。感激不尽

Posted by tiankangwei at 2011-06-29 12:20:21 on Problem 1321

#include <iostream>
using namespace std;

bool col[10];
char map[10][10];
int n,k,res;

void dfs( int r, int counter )
{
	if ( r >= n  )
		return;
	if ( counter == k )
	{
		res++;
		return;
	}
	for ( int i = 0; i < n; i++ )
	{
		if ( map[r][i] == '#' && col[i] == 0 )
		{
			col[i] = 1;
			dfs(r+1,counter+1);
			col[i] = 0;
		}
	}
	dfs(r+1,counter);
}

int main()
{
	while ( cin >> n >> k && ! (n == -1 && k == -1) )
	{
		getchar();
		memset(map,0,sizeof(map));
		memset(col,0,sizeof(col));
		for ( int i = 0; i < n; i++ )
			cin >> map[i];
	    res = 0;
		dfs(0,0);
		cout << res << 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