#include <leetcode.h>
|
static void | dfs (const vector< vector< bool > > &board, int line, int n, vector< vector< string > > &ans) |
|
static vector< string > | toStringVec (const vector< vector< bool > > &board) |
|
static bool | valid (const vector< vector< bool > > &board, int n, int x, int y) |
|
◆ dfs()
void leetcode::n_queens::Solution::dfs |
( |
const vector< vector< bool > > & | board, |
|
|
int | line, |
|
|
int | n, |
|
|
vector< vector< string > > & | ans ) |
|
staticprivate |
在文件 leetcode.cpp 第 8315 行定义.
8315 {
8316 if(line == n) {
8318 return;
8319 }
8320 for(int i = 0; i < n; i++) {
8321 if(
valid(board, n, line, i)) {
8322 vector<vector<bool>> next = board;
8323 next[line][i] = true;
8324 dfs(next, line + 1, n, ans);
8325 }
8326 }
8327 }
vector< vector< int > > ans
static bool valid(const vector< vector< bool > > &board, int n, int x, int y)
static vector< string > toStringVec(const vector< vector< bool > > &board)
static void dfs(const vector< vector< bool > > &board, int line, int n, vector< vector< string > > &ans)
引用了 dfs(), toStringVec() , 以及 valid().
被这些函数引用 dfs() , 以及 solveNQueens().
◆ solveNQueens()
vector< vector< string > > leetcode::n_queens::Solution::solveNQueens |
( |
int | n | ) |
|
|
static |
◆ toStringVec()
vector< string > leetcode::n_queens::Solution::toStringVec |
( |
const vector< vector< bool > > & | board | ) |
|
|
staticprivate |
在文件 leetcode.cpp 第 8348 行定义.
8348 {
8349 vector<string>
ans(board.size());
8350 for(int i = 0; i < board.size(); i++) {
8351 ostringstream oss;
8352 for(int j = 0; j < board[i].size(); j++) {
8353 oss << (board[i][j] ? 'Q' : '.');
8354 }
8356 }
8358 }
被这些函数引用 dfs().
◆ valid()
bool leetcode::n_queens::Solution::valid |
( |
const vector< vector< bool > > & | board, |
|
|
int | n, |
|
|
int | x, |
|
|
int | y ) |
|
staticprivate |
在文件 leetcode.cpp 第 8329 行定义.
8329 {
8330 for(int i = 0; i < x; i++) {
8331 if(board[i][y]) {
8332 return false;
8333 }
8334 }
8335 for(int i = x, j = y; i >= 0 && i < n && j >= 0 && j < n; i--, j--) {
8336 if(board[i][j]) {
8337 return false;
8338 }
8339 }
8340 for(int i = x, j = y; i >= 0 && i < n && j >= 0 && j < n; i--, j++) {
8341 if(board[i][j]) {
8342 return false;
8343 }
8344 }
8345 return true;
8346 }
被这些函数引用 dfs().
该类的文档由以下文件生成: