8皇后问题
来源:互联网 发布:python修改文件内容 编辑:程序博客网 时间:2024/06/11 07:55
bool check(vector<int> res) { for (int row = 0; row < res.size()-1; row++) { for (int col = row+1; col < res.size(); col++) { if (row - col == res[row] - res[col] || row - col == res[col] - res[row]) return false; } } return true;}void permQueen(vector<int> colIndex, int start, vector<vector<int> >& res) { if (start==colIndex.size()) res.push_back(colIndex); for (int i = start; i < colIndex.size(); i++) { swap(colIndex[start], colIndex[i]); permQueen(colIndex, start+1, res); swap(colIndex[start], colIndex[i]); }}int EightQueen() { //const int queens = 8; vector<int> colIndex = {0,1,2,3,4,5,6,7}; vector<vector<int> > res; permQueen(colIndex, 0, res); int cnt = 0; for (int i = 0; i < res.size(); i++) { if (check(res[i])) cnt++; } return cnt;}
0 0
- 8皇后问题和N皇后问题
- 8皇后问题改进~
- 8皇后问题
- 8皇后问题求解
- 8皇后问题
- 8皇后问题
- 8皇后问题算法
- 8皇后问题
- 8皇后问题
- 8皇后问题
- 8皇后问题
- 8皇后问题
- 8皇后问题
- 8皇后问题
- 【算法】8皇后问题
- 8皇后问题续
- 8皇后问题算法
- 8皇后问题
- windows API分类
- 共享单车在过度竞争中陷入互黑战
- 深入理解javascript原型和闭包(13)-【作用域】和【上下文环境】
- 使用PlantUML快速绘图
- 【完整版:深度学习环境配置】
- 8皇后问题
- 1106. Lowest Price in Supply Chain (25)
- jqery粘贴事件
- Android Service完全解析,关于服务你所需知道的一切(下)
- cookie学习
- 创建docker私有仓库
- Java多线程(二)- 常用方法
- 硬盘分区表知识——详解硬盘MBR
- Unity3D FPS