[Baekjoon 9663] N-Queen
Place one queen per row, mark attacked cells below it, and restore those marks when backtracking.
August 30, 2022
With one queen per row, the next step is to choose a column that is not under attack. When placing a queen, I marked the cells below it in the same column and both diagonals. After recursion, I removed only the marks added by that queen.
If row equals n, a complete arrangement has been found.
Check each column.
If safe: mark → recurse to the next row → restore marks.
Instead of trying every board coordinate, I reduced the search to one row at a time and marked attack ranges immediately to eliminate invalid branches.
Problem: Baekjoon · Code: View on GitHub