Title: The n-queens Puzzle is the problem of placing N Queens in an nxn chessboard such th At No, Queens attack. (Leetcode 51)
Given an integer n, return all distinct solutions to the n-queens puzzle.
Each solution contains a distinct board configuration of the n-queens ' placement, where ‘Q‘
and ‘.‘
both Indic Ate a queen and an empty space respectively.
For example,
There exist-distinct solutions to the 4-queens puzzle:
[ [". Q.. ", //solution 1 " ... Q ", " Q ... ",". . Q. "], ["]. Q. ", //Solution 2 " Q ... ", " ... Q ", ". Q.. "]
Reference frame:
class Solution {public: vector<vector<string>> solvenqueens ( int N) { //code }};
1. The Queen can be attacked in a straight line and slash in chess. That is to ask the N queen on the Board of the NxN not appear peers, the same column, with a slash to place.
The Queen's question was extended by the eight Queen's question. The N queen problem only has a solution when n=1 or n>=4.
2.N Queen problem is a classic case of backtracking, try to solve this problem with naive's backtracking method first.
N-queens N Queen Question