LeetCode N-Queens

2015-01-26 23:16:36 · 作者: · 浏览: 4

又是一个八皇后问题:

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 indicate a queen and an empty space respectively.

For example,
There exist two distinct solutions to the 4-queens puzzle:

[
 [".Q..",  // Solution 1
  "...Q",
  "Q...",
  "..Q."],

 ["..Q.",  // Solution 2
  "Q...",
  "...Q",
  ".Q.."]
]
\

class Solution {
public:
    vector
  
    > solveNQueens(int n) {
        this->N=n;
        memset(matrix,0,sizeof(matrix));
        dfs(0);
        return d;
    }
    int check(int x,int y)
        {
            for(int j=0;j
   
    mt; for(int i=0;i
    
      > d; int matrix[100][100]; };