After thinking about this question for a long time, I read the eight queens question. This question is more troublesome than the eight queens question: when the number of chess pieces is less than the number of Checker lines, we must continue to recursion and backtracking. Code directly (without any pruning)
# Include <iostream> <br/> using namespace STD; <br/> int Board [9] [9], Col [9], count; <br/> void DFS (int n, int K, int line) // K indicates the number of currently remaining pieces, line is the row to be tested. <br/>{< br/> int I, j; <br/> for (j = 1; j <= N; j ++) <br/> If (Board [Line] [J] &! Col [J]) <br/>{< br/> If (k = 1) <br/>{< br/> count ++; <br/> continue; <br/>}< br/> Col [J] = 1; <br/> for (I = line + 1; I <= N; I ++) <br/> DFS (n, K-1, I); <br/> Col [J] = 0; <br/>}< br/> int main () <br/>{< br/> int B, num, C, R; <br/> char CHR; <br/> while (scanf ("% d", & B, & num )) <br/>{< br/> If (B =-1 & num =-1) <br/> break; <br/> getchar (); <br/> for (r = 1; r <= B; r ++) <br/> {<br/> for (C = 1; C <= B; c ++) <br/>{< br/> scanf ("% C", & CHR); <br/> If (CHR = '#') <br/> Board [r] [c] = 1; <br/> else <br/> Board [r] [c] = 0; <br/>}< br/> getchar (); <br/>}< br/> If (num = 0 | B = 0) <br/>{< br/> printf ("0/N"); <br/> continue; <br/>}< br/> COUNT = 0; <br/> for (r = 1; r <= B-num + 1; r ++) <br/> {<br/> memset (COL, 0, sizeof (COL); <br/> DFS (B, num, R); <br/>}< br/> printf ("% d/N", count ); <br/>}< br/> return 0; <br/>}