Leetcode 52
//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的更多相关文章
- [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 ...
- LeetCode - 52. N-Queens II
52. N-Queens II Problem's Link --------------------------------------------------------------------- ...
- Leetcode 52 N-Queens II 回溯搜索
对于N-Queens的每种情况,回答出每种情况的N-Queens的排列数. l,r和c是每种类型的格子是否有棋子. l判断的是这样的对角线的格子 r判断的是这样的对 ...
- [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 ...
- Java实现 LeetCode 52 N皇后 II
52. N皇后 II n 皇后问题研究的是如何将 n 个皇后放置在 n×n 的棋盘上,并且使皇后彼此之间不能相互攻击. 上图为 8 皇后问题的一种解法. 给定一个整数 n,返回 n 皇后不同的解决方案 ...
- LeetCode(52)-Remove Linked List Elements
题目: Remove all elements from a linked list of integers that have value val. Example Given: 1 --> ...
- [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 ...
- Leetcode:52. N-QueensII
Description Follow up for N-Queens problem. Now, instead outputting board configurations, return the ...
- [LeetCode] 52. N皇后 II
题目链接 : https://leetcode-cn.com/problems/n-queens-ii/ 题目描述: n 皇后问题研究的是如何将 n 个皇后放置在 n×n 的棋盘上,并且使皇后彼此之间 ...
随机推荐
- Find them, Catch them---poj1703(并查集)
题目链接:http://poj.org/problem?id=1703 可以认为n个人和m句话: 每句话包含A a b;D a b; 刚开始关系不确定: A a b 就是问ab 是否同类: D a b ...
- java 字节流和字符流转换类InputStreamReader,OutPutStreamReader
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY2pjMjExMzIy/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA ...
- .NET、NET Framewor以及.NET Core的关系(二)
什么是CLR,.NET虚拟机? 实际上,.NET不仅提供了自动内存管理的支持,他还提供了一些列的如类型安全.应用程序域.异常机制等支持,这些 都被统称为CLR公共语言运行库. CLR是.NET类型系统 ...
- EasyUI Droppable 可放置
通过 $.fn.droppable.defaults 重写默认的 defaults. 用法 通过标记创建可放置(droppable)区域. <div class="easyui-dro ...
- 01 - spring mvc 概述及配置DispatcherServlet
1.Spring mvc 基于model2实现,整体框架流程如(图片来自百度): ①web容器接收到http请求,若匹配DispatcherServlet的请求映射路径(web.xml),则容器会交给 ...
- (转)SSIS处理导入数据时, 存在的更新, 不存在的插入
问题描述: 当你把数据从其他数据库, 或者是文本文件之类的其他数据源导入到目的数据库时, 有时希望在导入的处理中, 能够实现"数据存在时更新, 不存在时导入" 在之前, 一般是通过 ...
- python实现指定目录下批量文件的单词计数:并发版本
在 文章 <python实现指定目录下批量文件的单词计数:串行版本>中, 总体思路是: A. 一次性获取指定目录下的所有符合条件的文件 -> B. 一次性获取所有文件的所有文件行 - ...
- Qt无法调试Qvector
现象: 解决: 打开文件 $(VSDIR)\Common7\Packages\Debugger\autoexp.dat (VSDIR是本机Visual Studio的安装目录)把定义QVector和Q ...
- 如何解决tensorflow报:Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
答:使能AVX,AVX2和FMA来进行源码编译,这样可以提速噢 具体编译方法,请参考windows10下如何进行源码编译安装tensorflow
- linux下递归删除指定后缀名的文件
以删除当前目录到所有子目录下的后缀名为rej的文件为例: find . -name "*.rej" |xargs rm -f