Peaceful Queens Count
You are given an n × n chessboard. Some cells are cracked and cannot hold a piece; the rest are
sound.
Count the number of ways to place n queens on sound cells so that no two queens attack each
other. A queen attacks every other cell in its row, its column, and both of its diagonals, so a
valid placement has exactly one queen per row and exactly one queen per column, and no two queens
share a diagonal.
The input consists of T independent boards; solve each one.
Input
The first line contains an integer T (1 ≤ T ≤ 40), the number of boards.
Each board is described as follows:
- A line with one integer
n(1 ≤n≤ 14), the board size. nlines follow, each a string of exactlyncharacters over.and#. The character.marks a sound cell and#marks a cracked cell.
Output
For each board, print one line with a single integer: the number of valid placements of n
non-attacking queens that avoid every cracked cell.
Notes
In the first example, the board is empty and n = 4; the classic 4-queens puzzle has exactly 2
solutions.
In the second example, the cell in row 1, column 3 is cracked. That cell is used by one of the two 4-queens solutions, so only 1 placement remains.