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 的棋盘上,并且使皇后彼此之间 ...
随机推荐
- redis cluster 集群畅谈(一)
redis单机在大数据量情况的会出现瓶颈问题,通过redis 主从架构和 哨兵集群结合可以实现99.99% 高可用 .水平扩容支持更高QPS的解决方案. 在大数据量面前,主从架构结合哨兵集群的解决方案 ...
- Rochambeau---poj2912||zoj2751(并查集类似于食物链)
题目链接:http://poj.org/problem?id=2912 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1751 ...
- Max Sum Plus Plus---hdu1024(动态规划求M段的最大和)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1024 题意就是有n个数分成m段,求最大的和: dp[i][j]表示把 j 个数分成 i 段,选择第 j ...
- linux软件源配置
实操(虚拟机安装): 下载VMware,然后按照如下教程安装虚拟机: https://jingyan.baidu.com/article/c275f6ba07e269e33d756714.html ...
- JSP学习(第一课)
JSP页面组成: 比如: 打开网页,右键查看源代码: 打开网页: 注意: <%!%>里面定义的属性是成员属性,相当于类的属性,方法相当于是全局的方法,相当于是类里面的方法.但是它是不可以进 ...
- android 本地通知
NotificationManager manager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); Notificat ...
- Openstack(七)keystone
官方安装文档:https://docs.openstack.org/ocata/zh_CN/install-guide-rdo/index.html 7.1 keystone简介 Keystone 中 ...
- PAT 1082 Read Number in Chinese[难]
1082 Read Number in Chinese (25 分) Given an integer with no more than 9 digits, you are supposed to ...
- 模块讲解----subprocess模块
历史 #输出结果到屏幕上,并不返回执行状态os.system('dir')#保存命令的执行结果输出ret = os.popen('dir').read() 问题:上面2条是把命令结果保存下来了,但是返 ...
- linux进程间通讯的几种方式的特点和优缺点
# 管道( pipe ):管道是一种半双工的通信方式,数据只能单向流动,而且只能在具有亲缘关系的进程间使用.进程的亲缘关系通常是指父子进程关系.# 有名管道 (named pipe) : 有名管道也是 ...