POJ 1321: Checkerboard Issues

Source: Internet
Author: User

Checkerboard Issues
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 28067 Accepted: 13874

Description

In a given shape of the chessboard (the shape may be irregular) on the top of the pieces, chess pieces no difference. If you need to place any of the two pieces in the same row or column in the chessboard, please program the chessboard with a given shape and size, and put all the feasible arrangement C for the K pieces.

Input

The input contains multiple sets of test data.
The first row of each set of data is two positive integers, n K, separated by a space, indicating that the chessboard will be described in a n*n matrix and the number of pieces to be placed. N <= 8, K <= N
When 1-1 indicates the end of the input.
The next n lines describe the shape of the chessboard: N characters per line, where # represents the board area. Represents an empty area (the data guarantees that no extra blank lines or blank columns appear).

Output

For each set of data, give a line of output, the output is placed in the number of programs C (Data Assurance c<2^31).

Sample Input

2 #.. #4 4...#. #.. #.. #...-1-1

Sample Output

21st

Chess board, search from the top, the first guarantee that there is only one pawn per line, then mark a column of flag, so that each column has only one pawn. From the top down deep search can be.

That period of time is really, write deep search to write a feeling, now look at this topic may not write their own ...

Code:

#include <iostream> #include <algorithm> #include <cmath> #include <vector> #include <string > #include <cstring> #pragma warning (disable:4996) using namespace Std;int N,k,result;char value[15][15];int flag[15];void dfs (int i,int j,int num) {flag[j]=1;if (num==k) {Result++;flag[j]=0;return;} if (j>n| | I>n) Return;int h,g;for (g=i+1;g<=n;g++) {for (h=1;h<=n;h++) {if (flag[h]==0&&value[g][h]== ' # ') {DFS ( g,h,num+1);}}} flag[j]=0;} int main () {int I,j;while (cin>>n>>k) {if (n+k==-2) break;for (i=1;i<=n;i++) cin>>value[i]+1; memset (flag,0,sizeof (flag)); Result=0;for (i=1;i<=n;i++) {for (j=1;j<=n;j++) {if (value[j][i]== ' # ') DFS (j,i,1);}} Cout<<result<<endl;} return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

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.