#include<cstdio>
#include<cstring>
using namespace std;
int N, K;
const int MAX_N = 8 + 1;
char maze[MAX_N][MAX_N];
int count = 0;
int book[MAX_N];
bool avaliable(int a, int b)
{
if(book[b]) return false;
else if(maze[a][b] == '.') return false;
return true;
}
void dfs(int i, int now)
{
if(i > N)
return ;
else if(now == K)
{
count++;
return ;
}
else
{
for(int j = 0; j < N; ++j)
{
if(avaliable(i, j))
{
book[j] = 1;
dfs(i + 1, now + 1);
book[j] = 0;
}
}
dfs(i + 1, now);
}
}
int main()
{
while(true)
{
scanf("%d%d", &N, &K);
if(N == -1 || K == -1)
break;
for(int i = 0; i < N; ++i)
scanf("%s", maze[i]);
count = 0;
memset(book, 0, sizeof(book));
dfs(0, 0);
printf("%d\n", count);
}
return 0;
}
POJ1321 棋盘问题
最新推荐文章于 2019-10-25 15:45:09 发布