AcWing 1114. 棋盘问题
原题链接
简单
作者:
RanPg
,
2024-03-29 00:32:55
,
所有人可见
,
阅读 2
C++ 代码
#include<bits/stdc++.h>
using namespace std;
const int N = 10;
char w[N][N];
bool r[N];
int n, k, ans;
void dfs(int u, int cnt)
{
if(cnt > k)
{
ans ++;
return ;
}
if(u > n) return ;
for(int i = 1; i <= n; i ++)
{
if(w[u][i] == '#' && !r[i])
{
r[i] = true;
dfs(u + 1, cnt + 1);
r[i] = false;
}
}
dfs(u + 1, cnt);
}
int main()
{
while(1)
{
scanf("%d%d", &n, &k);
if(n == -1 && k == -1) break;
memset(r, false, sizeof r);
ans = 0;
for(int i = 1; i <= n; i ++)
for(int j = 1; j <= n; j ++)
cin >> w[i][j];
dfs(1, 1);
cout << ans << endl;
}
return 0;
}