//N皇后的基础上改了一点
class Solution {
public:
int totalNQueens(int n) {
int res = ;
vector<int> pos(n,-);
DFS(pos,,res);
return res;
}
void DFS(vector<int>& pos,int row,int& res){
int n = pos.size();
if(row == n){
res++;
}
else{
for(int i=;i < n;i++){
if(isfine(pos,row,i)){
pos[row] = i;
DFS(pos,row+,res);
pos[row] = -;
}
}
}
} bool isfine(vector<int>& pos,int row,int col){
for(int i=;i < row;i++){
if(pos[i] == col || abs(row-i) == abs(col-pos[i]))
return false;
}
return true;
} };

Leetcode 52的更多相关文章

  1. [LeetCode] 52. N-Queens II N皇后问题之二

    The n-queens puzzle is the problem of placing nqueens on an n×n chessboard such that no two queens a ...

  2. LeetCode - 52. N-Queens II

    52. N-Queens II Problem's Link --------------------------------------------------------------------- ...

  3. Leetcode 52 N-Queens II 回溯搜索

    对于N-Queens的每种情况,回答出每种情况的N-Queens的排列数. l,r和c是每种类型的格子是否有棋子. l判断的是这样的对角线的格子                   r判断的是这样的对 ...

  4. [LeetCode] 52. N-Queens II N皇后问题 II

    The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens ...

  5. Java实现 LeetCode 52 N皇后 II

    52. N皇后 II n 皇后问题研究的是如何将 n 个皇后放置在 n×n 的棋盘上,并且使皇后彼此之间不能相互攻击. 上图为 8 皇后问题的一种解法. 给定一个整数 n,返回 n 皇后不同的解决方案 ...

  6. LeetCode(52)-Remove Linked List Elements

    题目: Remove all elements from a linked list of integers that have value val. Example Given: 1 --> ...

  7. [leetcode]52. N-Queens II N皇后

    The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens ...

  8. Leetcode:52. N-QueensII

    Description Follow up for N-Queens problem. Now, instead outputting board configurations, return the ...

  9. [LeetCode] 52. N皇后 II

    题目链接 : https://leetcode-cn.com/problems/n-queens-ii/ 题目描述: n 皇后问题研究的是如何将 n 个皇后放置在 n×n 的棋盘上,并且使皇后彼此之间 ...

随机推荐

  1. 分区实践 A PRIMARY KEY must include all columns in the table's partitioning function

    MySQL :: MySQL 8.0 Reference Manual :: 23 Partitioning https://dev.mysql.com/doc/refman/8.0/en/parti ...

  2. 为什么 要弄清楚 mysql int(5) int(11) bigint 自建mysql主键id python random 科学计数法

    场景: 有1.2亿条问答数据,相同问题的不同答案为不同条的数据,且该表数据逐日递增: 第三方需求(不合理): 将问题.答案数据分别放入问题表.答案表: 问题表的主键为整数,在答案表中,每行数据有相应的 ...

  3. Python之numpy基本指令

    https://blog.csdn.net/mmm305658979/article/details/78745637 # -*- coding: utf-8 -*- 多加练习才是真 import n ...

  4. 人人网张铁安:Feed系统架构分析(转)

    原文:http://www.csdn.net/article/2010-07-26/277273 继成功举办首期TUP活动后,日前在北京丽亭华苑酒店鸿运二厅,由CSDN和<程序员> 杂志联 ...

  5. 通过pd.to_sql()将DataFrame写入Mysql

    循环创建表,并且创建主键.外键 import pandas as pd from sqlalchemy import create_engine from sqlalchemy.types impor ...

  6. mysql根据经纬度获取附近的商家

    create table geo( geo_id INT NOT NULL AUTO_INCREMENT, lng float NOT NULL, lat float NOT NULL, name ) ...

  7. ubuntu16.04 安装指定版本Node,升级npm到指定版本

    一.安装配置Node 1.下载(64位系统) wget https://nodejs.org/download/release/v10.1.0/node-v10.1.0-linux-x64.tar.g ...

  8. log4j2动态修改日志级别及拓展性使用

    一.供参考的完整日志配置 <?xml version="1.0" encoding="UTF-8"?> <!-- 配置LoggerConfig ...

  9. php根据路径获取文件名

    <?php // 根据路径返回文件名 $path = 'J:\abc\defg\hijk\一个文件夹\lmn\opq'; $path = iconv("UTF-8", &qu ...

  10. python webdriver 测试框架-数据驱动txt文件驱动,带报告的例子

    数据驱动txt文件驱动的方式,带报告 data.txt: gloryroad test||光荣之路 摔跤爸爸||阿米尔 超人||电影 data_driven_by_txt_file.py: #enco ...