C-Checkerboard IssuesTime
limit:MS
Memory Limit:10000KB
64bit IO Format:%i64d &%i64u SubmitStatusPracticePOJ 1321
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
I really suggest that when you read the topic to all the conditions to see, otherwise it will waste a lot of time, I have to guard against their own, I hope you can also be vigilant
/*author:2486memory:124 kbtime:329 mslanguage:c++result:accepted*/#include <cstdio> #include <cstring># Include <algorithm>using namespace Std;const int maxn=10;int N,k,cnt;char maps[maxn][maxn];bool VIS[MAXN][MAXN]; BOOL ist (int x,int y) {int ans=0; for (int i=0; i<n; i++) {ans+=vis[x][i]; Ans+=vis[i][y]; } if (ans>0) return false; return true;} void Dfs (int x,int y,int num) {int nx,ny; if (num==0) {cnt++; Return } if (x>=n) return; if (y+1>=n) {nx=x+1; ny=0; } else {nx=x; ny=y+1; } dfs (Nx,ny,num); if (maps[x][y]!= '. ') {if (ist (x, y)) {vis[x][y]=true; DFS (NX,NY,NUM-1); Vis[x][y]=false; }}}int Main () {while (~scanf ("%d%d", &n,&k)) {cnt=0; if (n==-1| | K==-1) break; for (int i=0; i<n; i++) scanf ("%s", Maps[i]); DFS (0,0,K); printf ("%d\n", CNT); } return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Checkerboard Problem-dfs