八皇后问题
来源:互联网 发布:有知投资管理有限公司 编辑:程序博客网 时间:2024/06/15 05:33
import java.util.*;public class Solution { public int totalNQueens(int n) { ArrayList<Integer> path = new ArrayList<>(); int result = 0; result = dfs(n,result,path,0); return result; } public static int dfs(int n,int result,ArrayList<Integer> path,int j){ if(j==n){ ++result; return result; } for(int i=0;i<n;i++){ path.add(i); if(Check(path,j)) result = dfs(n,result,path,j+1); path.remove(path.size()-1); } return result ; } public static boolean Check(ArrayList<Integer> path,int j){ for(int i=0;i<j;i++){ if(path.get(i) == path.get(j) || Math.abs(i-j)==Math.abs(path.get(i)- path.get(j))) return false; } return true; }}
阅读全文
0 0
- 八皇后 n皇后 问题
- 八皇后N皇后问题
- 八皇后问题
- 八皇后问题
- 八皇后问题
- 八皇后问题(2)
- 八皇后问题(3)
- 八皇后问题
- 八皇后问题程序
- 浅谈八皇后问题
- 八皇后问题
- 八皇后问题
- 八皇后问题
- 八皇后问题
- 八皇后问题求解
- 八皇后问题
- 八皇后问题
- 八皇后问题
- javascript某标签的鼠标滚动事件取消效果或实现其他自定义效果
- max与min
- 利用git上传文件到远程仓库
- Mac 系统ReactNative环境搭建以及Node版本切换
- 开发工具
- 八皇后问题
- oracle导出sequence的SQL语句
- iOS FMDB数据库实现增删改查
- python数据类型(下)
- 计算机视觉中的多视图几何学习笔记
- 581. Shortest Unsorted Continuous Subarray
- android:descendantFocusability用法简析
- meshgrid
- iOS APP开发全局token的使用