1. //N皇后的基础上改了一点
    class Solution {
  2. public:
  3. int totalNQueens(int n) {
  4. int res = ;
  5. vector<int> pos(n,-);
  6. DFS(pos,,res);
  7. return res;
  8. }
  9. void DFS(vector<int>& pos,int row,int& res){
  10. int n = pos.size();
  11. if(row == n){
  12. res++;
  13. }
  14. else{
  15. for(int i=;i < n;i++){
  16. if(isfine(pos,row,i)){
  17. pos[row] = i;
  18. DFS(pos,row+,res);
  19. pos[row] = -;
  20. }
  21. }
  22. }
  23. }
  24.  
  25. bool isfine(vector<int>& pos,int row,int col){
  26. for(int i=;i < row;i++){
  27. if(pos[i] == col || abs(row-i) == abs(col-pos[i]))
  28. return false;
  29. }
  30. return true;
  31. }
  32.  
  33. };

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. Javascript计算星座

    今天看群里一哥们折腾得挺热乎,手痒随便写了一个DEMO,供初学者参考. 重点,写程序先定注释,明确思路后再写具体代码. //星座定义 var constellations = [ {"Sta ...

  2. acceptorThreadCount

    Apache Tomcat 7 Configuration Reference (7.0.92) - The HTTP Connector https://tomcat.apache.org/tomc ...

  3. 【css flex】将多个<div>放在同一行

    使用style里的flex属性 默认情况下,一个div独占一行 使用css选择器给外层div加上以下flex属性,则该div的子div可以在同一行中显示, .runs-paginator-flex-c ...

  4. Java中参数传递时值传递的机制分析

    参数传递是什么?      在C的函数或是JAVA的方法中,向一个函数或方法内部传递一个参数,比如:   void fun( int num ){     num+=2 ; }   int a = 3 ...

  5. MVC模式:python案例

    quotes = ('A man is not complete until he is married. Then he is finished.', 'As I said before, I ne ...

  6. 1040. 有几个PAT(25)

    原题: https://www.patest.cn/contests/pat-b-practise/1040 思路: 先给大家扔个测试PAPAATTPATTT, 人工查一下这段字符串能组成 34个PA ...

  7. fold change的意义[转载]

    转自:https://zhidao.baidu.com/question/2052933434631672387.html 1.解释 解释:表达值倍数变化 ,分析,消除可能的混杂因素,必要时可以用读段 ...

  8. Solr安装步骤

    一.Solr概述 1.什么是Solr Solr 是Apache下的一个顶级开源项目,采用Java开发,它是基于Lucene的全文搜索服务器.Solr提供了比Lucene更为丰富的查询语言,同时实现了可 ...

  9. 模块讲解----subprocess模块

    历史 #输出结果到屏幕上,并不返回执行状态os.system('dir')#保存命令的执行结果输出ret = os.popen('dir').read() 问题:上面2条是把命令结果保存下来了,但是返 ...

  10. 1 - bootstrap基本模板

    bootstrap 3.x 下载地址:http://v3.bootcss.com/ 基本模板如下: <!DOCTYPE html> <html lang="zh-cn&qu ...