AcWing 1114. 棋盘问题
原题链接
简单
作者:
continue_8
,
2024-04-08 21:52:16
,
所有人可见
,
阅读 1
#include<iostream>
using namespace std;
const int N=10;
char g[N][N];
int n,k;
int res;
bool st[N];
void dfs(int u,int cnt){//按行来遍历
if(cnt==k){
res++;
return ;
}
if(u==n) return ;
for(int i=0;i<n;i++){
if(!st[i]&&g[u][i]=='#'){
st[i]=true;
dfs(u+1,cnt+1);
st[i]=false;
}
}
//如果前面(下的棋数符合题目要求,方案++),就会返回,导致到不了下一行,这里让他强行往下走一行
dfs(u + 1, cnt);
}
int main(){
while(cin>>n>>k&& n > 0 && k > 0){
for(int i=0;i<n;i++)
cin>>g[i];
res=0;
dfs(0,0);
cout<<res<<endl;
}
return 0;
}