Board Problems
Time limit:1000 ms |
|
Memory limit:10000 K |
Total submissions:22144 |
|
Accepted:10988 |
Description
There is no difference in placing a piece on a given-shape chessboard (which may be irregular. It is required that any two chess pieces should not be placed in the same row or column of the board. Please program to solve all feasible placement schemes C for all K chess pieces with a given shape and size.
Input
The input contains multiple groups of test data.
The first row of each group of data is two positive integers, n k, separated by a space, indicating that the board will be described in an N * n matrix, and the number of pieces placed. N <= 8, k <= N
If it is-1-1, the input ends.
The next n lines describe the shape of the Board: each line has n characters, where # indicates the board area, and .. indicates the blank area (no extra blank rows or columns are required for data ).
Output
For each group of data, a single line of output is provided, and the number of solutions placed in the output is C (Data guarantee is C <2 ^ 31 ).
Sample Input
2 1 #... #4 4... #-1-1
Sample output
21
# Include <iostream> # include <cstring> using namespace STD; int n, m, ans; int V [10]; char C [10] [10]; void DFS (int r, int K) {int I, j; If (k = m) ans ++; else for (I = R + 1; I <N; I ++) for (j = 0; j <n; j ++) if (C [I] [J] = '#'&&! V [J]) {v [J] = 1; DFS (I, k + 1); V [J] = 0 ;}} int main () {While (CIN> N> m) {memset (v, 0, sizeof (v); If (n =-1 & M =-1) break; int I; for (I = 0; I <n; I ++) scanf ("% s", C [I]); ans = 0; DFS (-1, 0); cout <ans <Endl;} return 0 ;}
Poj 1321 board problem search