CSES-Solutions icon indicating copy to clipboard operation
CSES-Solutions copied to clipboard

Create Alternate Solution

Open shatanshu3006 opened this issue 2 years ago • 1 comments

This is another solution for the CSES "ChessBoard and Queens" Problem.

shatanshu3006 avatar Dec 23 '22 13:12 shatanshu3006

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

shatanshu3006 avatar Dec 23 '22 13:12 shatanshu3006