#188HardBacktracking· N-Queens with Bitmask Pruning
Museum Guard Placements
Input format
`n`: the side length of the floor.
Output format
An integer: the number of valid placements.
Examples
Input: n = 4
Output: 2
On a 4 x 4 floor exactly two placements work: they are mirror images of each other.
Input: n = 1
Output: 1
A single tile holds the single guard.
Input: n = 3
Output: 0
Three guards cannot be placed on a 3 x 3 floor without two of them seeing each other, so the count is 0.
Constraints
- 1 <= n <= 12
Study first
- #backtracking
- #bit-manipulation
- #recursion
- #counting