N-Queens II
2014-05-05 22:28
302 查看
class Solution { public: int totalNQueens(int n) { if(n<=0) return 0; int result=0; vector<int> table(n,0); next(n,table,0,result); return result; } void next(const int n,vector<int> &table,const int curRow,int &result) { for(int i=0;i<n;i++) { int j=0; for(;j<curRow;j++) { if(i==table[j] || abs(i-table[j])==(curRow-j)) break; } if(j==curRow) { if(curRow!=n-1) { table[curRow]=i; next(n,table,curRow+1,result); } else { result++; return; } } } return; } };
相关文章推荐
- Win2003利用dfs(分布式文件系统)在负载均衡下的文件同步配置方案
- win2003分布式文件系统(dfs)配置方法[图文详解]
- win2003分布式文件系统及其部署 图文教程
- DFS使用方法总结
- FastDFS注意事项
- 无忧技术带您预览DFS(分布式文件系统)管理控制台
- C 语言实现迷宫 DFS算法
- 一幅图弄清DFT与DTFT,DFS的关系
- HDFS---Namenode
- HDFS ---- Services startup
- ZOJ Problem Set - 1711 解题报告
- ZOJ Problem Set - 2412解题报告
- ZOJ Problem Set - 1457 解题报告
- POJ1979 Red and Black 题解
- Timus 1557 Network Attack DFS+各种各种...
- [LeetCode] Permutations
- [LeetCode] Permutations II
- [LeetCode] Combination Sum
- [LeetCode] Combination Sum II
- [LeetCode] Generate Parentheses