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 doNotHave at 2018-08-11 20:19:36 on Problem 1321
#include <iostream>
#include <cstdio>

const int maxn = 10;
char chessboard[maxn][maxn+1];
int n, k;
bool visit[maxn] = {};

int dfs(int row, int amount){
	if(amount == 0){
		return 1;
	}
	int res = 0;
	for(int i=0; i < n; ++i){
		if(chessboard[row][i] == '#' && !visit[i]){
			visit[i] = true;
			res += dfs(row+1, amount-1);
			visit[i] = false;
		}
	}
	return res;
}

int main(){
	while(scanf("%d%d", &n, &k), n != -1){
		for(int i=0; i < n; ++i){
			scanf("%s", chessboard[i]);
		}
		int ans = 0;
		for(int i=0; i <= n-k; ++i){
			ans += dfs(i, k);
		}
		printf("%d\n", ans);
	} 
	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