Leetcode no. 52
2016-04-14 16:48
447 查看
52. N-Queens II
Follow up for N-Queens problem.
Now, instead outputting board configurations, return the total number of distinct solutions.
Follow up for N-Queens problem.
Now, instead outputting board configurations, return the total number of distinct solutions.
public class Solution { int count=0; public int totalNQueens(int n){ solveNQueens(0, 0, n, new int ); return count; } private void solveNQueens(int row, int col, int n, int[] column){ if (row == n) count++; else{ for (int i = col; i < n; i++) { column[row]= i; boolean f= true; for (int r = row-1, lc= i-1, rc= i+1; r>=0 ; r--,lc--,rc++ ) { if (column[r]== i || column[r]==lc || column[r]==rc) f= false; } if (f) solveNQueens(row+1, 0, n, column); } } } }
相关文章推荐
- Ubuntu Server 13.10安装配置图解教程
- 对每个边缘求最小外接矩形,通过最小矩形提取每个边缘
- 操作系统——进程与线程笔记
- 快速排序 和 希尔排序
- Jackson学习笔记(一)
- 运维通用python脚本框架
- plupload使用指南(转)
- 循环(7)
- spring注解注入:<context:component-scan>详解
- 翻译_Understanding JSON(理解json)
- one or more constraints have not been satisfied
- NSCharacterSet
- Cordova系列学习教程02 开发环境的准备和运行
- strace在线上环境的troubleshooting
- VB程序语言3
- vs2010操作 office2010自我笔记
- Jackson学习笔记(二)
- 10的阶乘
- Intent 用法总结
- SQL语言的四种类型