📄 pku1321.cpp
字号:
#include <stdio.h>
#include <string.h>
int X, Y, XX;
char Map[10][10];
int stX[10], stY[10];
int cnt;
void DFS(int s, int n)
{
int x, y;
if (n == Y)
{
cnt++;
return;
}
if (s >= XX)
{
return;
}
while (s < XX)
{
if (Map[s / X][s % X] == '#')
{
break;
}
s++;
}
if (s >= XX)
{
return;
}
x = s / X;
y = s % X;
if (stX[x] == 0 && stY[y] == 0)
{
stX[x] = 1;
stY[y] = 1;
DFS(s + 1, n + 1);
stX[x] = 0;
stY[y] = 0;
}
DFS(s + 1, n);
}
void Solve()
{
int i, j;
XX = X * X;
for (i = 0; i < X; i++)
{
scanf("%s", Map[i]);
}
cnt = 0;
memset(stX, 0, sizeof(stX));
memset(stY, 0, sizeof(stY));
DFS(0, 0);
printf("%d\n", cnt);
}
int main()
{
while (scanf("%d %d", &X, &Y) != -1)
{
if (X == -1 && Y == -1)
{
break;
}
Solve();
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -