太简单了
没啥好说的
存个档
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
const int N=1e9;
int n,k,ans;
string a[9];//map
bool vis[9];//column
void dfs(int x,int step){//current line
if(step==k){ans++;return;}
else{
for(int j=x;j<n;j++){
for(int i=0;i<n;i++){
if(a[j][i]=='#'&&!vis[i]){
vis[i]=1;
dfs(j+1,step+1);
vis[i]=0;
}
}
}
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
while(cin>>n>>k){
if(n==-1)return 0;
for(int i=0;i<n;i++)cin>>a[i];
memset(vis,0,sizeof(vis));
ans=0;
dfs(0,0);
cout<<ans<<endl;
}
return 0;
}
原文地址:https://www.cnblogs.com/guaguastandup/p/10347462.html
时间: 2024-11-23 07:25:34