Checkerboard Issues
Time Limit: 1000MS |
|
Memory Limit: 10000K |
Total Submissions: 29121 |
|
Accepted: 14434 |
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
Source
#include <cstdio>#include<cstring>#defineMAX 9using namespacestd;CharMap[max][max];intAns,n,k,count;BOOLVis[max];voidDFS (intIndex//Line{ if(index>=n)//the lines are full and the end,> is convenient to continue backtracking return; for(intI=0; i<n; i++)//column { if(map[index][i]=='#'&&!vis[i])//On the board, and this column didn't pass.{Vis[i]=1;//Mark is placedcount++;//number of pieces to be placed if(count==k)//The number of pieces is equal to the titleans++;//Programme plus one ElseDFS (Index+1);//Not required, continue to recursion//Key Experiencecount--;//backtrack to find another solutionvis[i]=0; }} DFS (Index+1);//when Lie}intMain () { while(SCANF ("%d%d", &n,&k) &&n!=-1) {ans=0; memset (Vis,0,sizeof(VIS)); for(intI=0; i<n; i++) scanf ("%s",&Map[i]); DFS (0); printf ("%d\n", ans); } return 0;}
poj-1321-Checkerboard Issues