| 1 | #include <set> |
| 2 | |
| 3 | int nQueens(int n) { |
| 4 | int res = 0; |
| 5 | std::set<int> diagonalsSet; |
| 6 | std::set<int> antiDiagonalsSet; |
| 7 | std::set<int> colsSet; |
| 8 | dfs(0, diagonalsSet, antiDiagonalsSet, colsSet, n, res); |
| 9 | return res; |
| 10 | } |
| 11 | |
| 12 | void dfs(int r, std::set<int>& diagonalsSet, std::set<int>& antiDiagonalsSet, std::set<int>& colsSet, int n, int& res) { |
| 13 | // Termination condition: If we have reached the end of the rows, |