CSES-Solutions
CSES-Solutions copied to clipboard
Create Alternate Solution
This is another solution for the CSES "ChessBoard and Queens" Problem.
Using Backtracking
Since the bounds are small, we can recursively backtrack over all ways to place the queens, storing the current state of the board.
Then, we can try to place a queen at all squares $x, y$ if it isn't attacked by a queen or blocked and recurse, before removing this queen and backtracking.
Finally, when we have placed all the queens and the board's state is valid, then increment the answer.
Copy