Chinese problem, title no longer explained, simple DFS;
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cctype>
BOOL Maps[10][10];//maps make a chessboard, judge this point can play chess maps[0][i] used to record column I can play chess
int N, k, ans, Hang;//hang represents the moment in the first few lines of chess
void DFS (int k)
{
if (k = = 0) {//pieces are put out
ans++;
Return
}
if (Hang > N)//The number of rows checked is greater than or equal to N, at which point K is not equal to 0;
Return
if (N-hang + 1 < k)//The number of pieces left is not enough
Return
hang++;
for (int j = 1; J <= N; j + +) {
if (Maps[0][j]) continue;
if (!maps[hang][j]) continue;
MAPS[0][J] = true;
DFS (k-1);
MAPS[0][J] = false;
}
If there are no pieces to put on this line, check the next line
DFS (k);
hang--;
}
int main ()
{
Char ch;
while (~SCANF ("%d%d", &n, &k), n! =-1 | | K! =-1) {
Memset (maps, false, sizeof);
Ans = 0;
for (int i = 1; I <= n; i++) {
scanf ("");
for (int j = 1; J <= N; j + +) {
scanf ("%c", &ch);
if (ch = = ' # ') maps[i][j] = true;
}
}
Hang = 1;
for (int j = 1; J <= N; j + +) {
if (Maps[0][j]) continue;
if (!maps[hang][j]) continue;
MAPS[0][J] = true;
DFS (k-1);
MAPS[0][J] = false;//backtracking
}
DFS (k);
printf ("%d\n", ans);
}
}
POJ 1321 Checkerboard Issues