POJ 1321 Checkerboard Issues

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.