#include<iostream>
#include<cstring>
using namespace std;
const int N=22;
int n,k;
int res,cnt;
char s[N][N];
bool col[N];
void dfs(int u){
if(cnt == k){
res++;
return ;
}
if(u==n) return ;
for(int i=0;i<n;i++){
if(s[u][i] == '#' && !col[i]){
cnt++;
col[i] = true;
dfs(u+1);
col[i] = false;
cnt--;
}
}
dfs(u+1);
}
int main(){
while(scanf("%d%d",&n,&k)){
if(n==-1 && k==-1) break;
for(int i=0;i<n;i++) scanf("%s",s[i]);
res = cnt = 0;
memset(col,false,sizeof col);
dfs(0);
printf("%d\n",res);
}
}
棋盘问题(c++求解)
最新推荐文章于 2024-05-17 18:19:24 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)