题意 中文
简单的搜索题 标记列是否已经有子进行深搜即可 k可能小于n 所以每行都有放子或不放子两种选择
#include <cstdio>
using namespace std;
const int N = 10;
int n, k, ans, v[N];
char g[N][N];
void dfs(int r, int cnt)
{
if(cnt >= k) ++ans;
if(r >= n || cnt >= k) return;
for(int c = 0; c < n; ++c) //第r行c列放一个子
if((!v[c]) && g[r][c] == '#')
v[c] = 1, dfs(r + 1, cnt + 1), v[c] = 0;
dfs(r + 1, cnt); //第r行不放子
}
int main()
{
while(~scanf("%d%d", &n, &k), n + 1)
{
for(int i = 0; i < n; ++i)
scanf("%s", g[i]);
dfs(ans = 0, 0);
printf("%d\n", ans);
}
return 0;
}
Description
Input
Output
Sample Input
2 1 #. .# 4 4 ...# ..#. .#.. #... -1 -1
Sample Output
2 1
原文:http://blog.csdn.net/acvay/article/details/44626317