AcWing 1114. 棋盘问题
原题链接
简单
作者:
自由周某
,
2020-09-28 22:15:59
,
所有人可见
,
阅读 420
#include<iostream>
#include<cstring>
using namespace std;
const int N = 10;
char court[N][N]; //存图
bool row[N], col[N];
int res;
int n , k;
void dfs(int x, int y, int cnt){
if(cnt == k ){
res ++ ;
return ;
}
if(y == n ) y = 0, x++;
if(x == n && y == 0) return ;
if(!col[y] && !row[x] && court[x][y] == '#'){
row[x] = col[y] = true;
dfs(x , y + 1, cnt + 1);
row[x] = col[y] = false;
}
dfs(x, y + 1, cnt);
}
int main(){
while(cin >> n, n != -1){
memset(col, 0, sizeof col);
memset(row, 0, sizeof row);
res = 0;
cin >> k;
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++) cin >> court[i][j];
dfs(0, 0, 0);
cout << res << endl;
}
return 0;
}