#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int n, k;
const int N = 10;
char mp[N][N];
int num;
bool row[N];
int sum;
typedef struct {
int x, y;
}Position;
void Init() {
num = 0;
memset(row, true, sizeof(row));
sum = 0;
}
bool IsDone(int step) {
return (step == k);
}
void SetVis(Position pos, bool cnt) {
row[pos.x] = cnt;
}
bool IsValid(Position pos) {
bool legal, r;
legal = (mp[pos.x][pos.y] == '#');
r = row[pos.x];
return legal && r;
}
Position GetNewPos(int i, int step) {
int y = step;
int x = i;
Position next_pos = {x, y};
return next_pos;
}
void Try(int col) {
if (IsDone(sum)) {
++num;
return;
}
if (col == n) return;
for (int i = 0; i < n; ++i) {
Position cur_pos = GetNewPos(i, col);
if (!IsValid(cur_pos)) continue;
// cout << "i = " << i << ends << "k = " << k << ends << mp[i][col] << endl;
SetVis(cur_pos, false);
++sum;
Try(col + 1);
SetVis(cur_pos, true);
--sum;;
}
Try(col + 1); // 这一步很重要,如果对于第i列的每个值都不行的话,
// 就要遍历第i + 1列;通过在循环外加这一行代码实现。
}
int main() {
while (scanf("%d%d", &n, &k) && (n != -1 && k != -1)) {
Init();
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j)
cin >> mp[i][j];
}
Try(0);
cout << num << endl;
}
return 0;
}
垃圾poj,不识别头文件,吐槽归吐槽