F-Checkerboard Issues Time
limit:1000MS
Memory Limit:10000KB
64bit IO Format:%i64d &%i64 U Submit Status Practice POJ 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
Or that sentence, must pay attention to read the question, must! Must! Must!!!
This question Kiven hand after extensive reading, established the idea of Dfs, but how also can not tune out the second set of data, and then read through the test instructions found that the original ' # ' is the place to put pieces!! The question person does not follow the routine card!!
Well, let's take a look at Test instructions:
Yes, right! This is a Chinese question.
In summary DFS idea, AC code:
1#include <iostream>2#include <cstdio>3#include <cstring>4 using namespacestd;5 Const intmax=Ten;6 7 CharMap[max][max];8 intTemp[max];//number of line points9 intN,k,sum,num;//sum output value num already put numberTen One A voidDasointi) {//DFS (not very skilled, strengthened on weekends) - if(num==k) { -sum++; the return; - } - if(i>=N) { - return; + } - for(intj=0; j<n;j++) + if(!temp[j]&&map[i][j]=='#') A { attemp[j]=1; -num++; -DFS (i+1); -temp[j]=0; -num--; - } in -DFS (i+1); to } + - intMain () { the inti,j; * while(SCANF ("%d%d", &n,&k) &&n!=-1&&k!=-1){ $ Panax Notoginseng -GetChar ();//GetChar () is not good enough. the for(i=0; i<n;i++){ + for(j=0; j<n;j++){ Ascanf"%c",&map[i][j]); the GetChar (); + } - } $memset (temp,0,sizeof(temp)); $sum=0; num=0; -DFS (0); -printf"%d\n", sum);//added a "&"!! Too much detail. the } - return 0;Wuyi}
A lot of problems were found when writing a question, the use of DSF is not proficient, the input format of strings need to be strengthened.
F-Checkerboard Issues