The problem is simple DFS, yes, I did it for one hours.
The problem is given a chessboard, which. is blank, can not play chess pieces, #是可以放棋子的位置. When placing a piece, only one pawn can be placed in the same row.
Input N,k
Then enter the N*n board, #或者. , how many ways to put the pieces.
·· DFS (S,KK) indicates how many pieces have been placed in the first line.
Of course, starting with DFS (0,0).
Initially DFS (I+1,KK++1) was written as DFS (s+1,kk+1), and then always tle.
1#include <cstdio>2#include <cstring>3 Charmap[Ten][Ten];4 BOOLvis[Ten];5 intAns,k,n;6 voidDFS (intSintKK)7 {8 if(kk==k) {9ans++;Ten return ; One } A for(inti=s;i<n;i++){ - for(intj=0; j<n;j++){ - if(!vis[j]&&map[i][j]=='#'){ thevis[j]=true; -DFS (i+1, kk+1); -vis[j]=false; - } + } - } + } A intMain () at { - while(SCANF ("%d%d",&n,&k)) { - if(n==-1&&k==-1) - Break; - for(intI=0; i<n;i++) -scanf"%s", Map[i]); inmemset (Vis,false,sizeof(Vis)); -ans=0; toDFS (0,0); +printf"%d\n", ans); - } the return 0; *}
View Code
Checkerboard Problem poj1321