8.8-N皇后
来源:互联网 发布:怎么用淘宝助理 编辑:程序博客网 时间:2024/06/05 14:42
Write an algorithm to print all ways of arranging eight queens on a chess board so that none of them share the same row, column or diagonal.
#include <iostream>using namespace std;int n=8;int tot=0;int col[8];void dfs(int cur){ if(cur==n) tot++;//or print board else for(int i=0; i<n; i++) { int ok=1; col[cur]=i; for(int j=0; j<cur; j++) if(col[cur]==col[j] || cur-col[cur]== j-col[j] || cur+col[cur]==j+col[j]) { ok=0; break; } if(ok) dfs(cur+1); }}int main(){ dfs(0); cout << tot << endl; return 0;}
0 0
- 8.8-N皇后
- n皇后
- N皇后
- N 皇后
- n皇后
- n皇后
- N皇后
- N皇后
- n皇后
- n 皇后
- N皇后
- N皇后
- N皇后
- N皇后
- n皇后
- N皇后
- N皇后
- N皇后
- eclipse智能提示
- 问题2:CentOS 下修改 core file size 失败解决
- 数组函数20140908study
- AsyncTask异步任务
- 隐马尔可夫模型(HMM) HDU4865 Peter's Hobby
- 8.8-N皇后
- Hibernate简介
- BestCoder Round #8
- Node.js + Express + MongoDB教程
- 数据库范式
- PHP CURL 发送和接收XML数据,并用$HTTP_RAW_POST_DATA接收
- C++面试题总结
- Android NDK编程(一)
- 多线程下载的原理