#include <iostream>
#include "stdafx.h"
using namespace std;
int n,k;
int total;
char c;
int data[10][10];
int flag[10];
void dfs(int layer, int num){
if(num == 0) {
total++;
return;
}
if(layer > n) {
return;
}
for(int col=1; col<=n; col++){
if(data[layer][col] == 1 && flag[col] == 0){
flag[col] = 1;
dfs(layer+1, num-1);
flag[col] = 0;
}
}
dfs(layer+1, num);
}
int main(){
while(true){
cin >> n;
cin >> k;
if(n==-1 && k==-1){
break;
}else{
memset(data, 0, sizeof(data));
memset(flag, 0, sizeof(flag));
total = 0;
for(int i=1; i<=n; i++){
for(int j=1; j<=n; j++){
cin >> c;
if(c == '#') data[i][j] = 1;
else data[i][j] = 0;
}
}
}
dfs(1,k);
cout << total << endl;
}
return 0;
}
poj1321
最新推荐文章于 2017-03-10 11:09:06 发布