博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[LeetCode]N-Queens 八皇后问题扩展(经典深层搜索)
阅读量:6994 次
发布时间:2019-06-27

本文共 1223 字,大约阅读时间需要 4 分钟。

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

Given an integer n, return all distinct solutions to the n-queens puzzle.

Each solution contains a distinct board configuration of the n-queens' placement, where 'Q' and '.' both indicate a queen and an empty space respectively.

For example,

There exist two distinct solutions to the 4-queens puzzle:

[ [".Q..",  // Solution 1  "...Q",  "Q...",  "..Q."], ["..Q.",  // Solution 2  "Q...",  "...Q",  ".Q.."]]
參考:LeetCode 题解
戴方勤 (soulmachine@gmail.com)
https://github.com/soulmachine/leetcode
public class Solution {	boolean[] column = null;	boolean[] diag = null;	boolean[] anti_diag = null;	int[]C = null;	String model = null;    public List
solveNQueens(int n) { column = new boolean[n]; diag = new boolean[2*n]; anti_diag = new boolean[2*n]; C = new int[n];//Q在第i行的第几列 List
res = new ArrayList<>(); dfs(0,res,n); return res; } private void dfs(int row,List
res,int n){ if(row==n){ String [] str = new String[n]; for(int i=0;i

版权声明:本文博客原创文章。博客,未经同意,不得转载。

你可能感兴趣的文章
从0到上线开发企业级电商项目_前端_01_sublime使用技巧
查看>>
Android 百分比布局库(percent-support-lib)
查看>>
1、MLflow:一个开源的机器学习平台
查看>>
MySQL必知必会
查看>>
Linux的企业-监控Cacti
查看>>
极速理解设计模式系列:15.中介者模式(Mediator Pattern)
查看>>
SQL Server-聚焦过滤索引提高查询性能(十)
查看>>
树莓派:最好的安排
查看>>
我看好互联网阅读(r11笔记第63天)
查看>>
关于奇怪的并行进程分析(三)
查看>>
和开发讨论的一个数据变更需求
查看>>
[20150604]关于同义词的问题3.txt
查看>>
Java实现视频网站的视频上传、视频转码、视频关键帧抽图, 及视频播放功能
查看>>
VMware 虚拟化编程(11) — VMware 虚拟机的全量备份与增量备份方案
查看>>
PostgreSQL 自定义自动类型转换(CAST)
查看>>
Clash Detection
查看>>
Windows Lnk远程代码执行漏洞(CVE-2017-8464)利用测试
查看>>
专访友友新创姚宏宇 谈云计算中间件
查看>>
存储圈一个叫柏科数据的公司
查看>>
服务企业“新两化” 用友迈进3.0时代
查看>>