POJ - 1321 棋盘问题
#include<iostream>
#include<cstring>
using namespace std;
#define maxn 9
int mmp[maxn][maxn];
bool checky[maxn];
long long n,k,ans;
void dfs(long long x, long long num){
if(num==k){
//cout<<x<<endl;
ans++;return ;
}
for(long long i=x+1;i<=n;i++){
for(long long j=1;j<=n;j++){
if(mmp[i][j]&&!checky[j]){
checky[j]=true;
dfs(i,num+1);
checky[j]=false;
}
}
}
}
int main(){
char get;
while(cin>>n>>k){
if(n==-1&&k==-1){
break;
}
ans=0;
memset(mmp,0,sizeof(mmp));
memset(checky,0,sizeof(checky));
for(long long i=1;i<=n;i++){
for(long long j=1;j<=n;j++){
cin>>get;
if(get=='#') mmp[i][j]=1;
}
}
dfs(0,0);
cout<<ans<<endl;
}
return 0;
}