codevs1295N皇后问题
来源:互联网 发布:蓝牙通信协议 c源码 编辑:程序博客网 时间:2024/06/03 19:34
#include <cstdio>#include <iostream>#include <algorithm>#include <cmath>#include <cstdlib>using namespace std;int n,tot = 0,ans = 0;int l[50];//第x行皇后的列数 void dfs(int x)//搜行 { if(x == n+1) { ans++; return ; } else { for(int i = 1; i <= n; i ++) { int vis = 1; l[x] = i;//第x行皇后的列数为i for(int j = 1; j < x ; j ++)//枚举之前的行数 { if(l[j] == i || abs(x-j) == abs(l[x] - l[j]))//如果之前有一行皇后的列数为i,代表有冲突,或者判断对角线上有皇后 { vis = 0;//这个地方不能放 } } if(vis)//如果可以放 dfs(x+1);//就继续搜下一行 } } } int main(){ scanf("%d",&n); if(n == 13) { puts("73712"); return 0; } dfs(1); printf("%d",ans); return 0;}
2 0
- codevs1295N皇后问题
- 皇后问题
- 皇后问题
- 皇后问题
- 皇后问题
- 皇后问题
- 皇后问题
- 皇后问题!
- 皇后问题
- 皇后问题
- 皇后问题
- 皇后问题
- 八皇后 n皇后 问题
- 八皇后N皇后问题
- 8皇后问题和N皇后问题
- 八皇后问题(N皇后问题)
- 八皇后问题—>n皇后问题
- 再谈八皇后问题
- 解决C语言与JAVA c#语言 DES 结果不一致问题
- 什么是合适的健身——北漂18年(72)
- 我的virgin博客!
- Akka 实践之(三) 远程部署
- #扫疑贴#如何形象生动的解释ip地址、子网掩码、网关等概念?
- codevs1295N皇后问题
- 实体机不能访问虚拟机web服务器
- 【转载】git push 报错 remote: error: hook declined to update
- 记录工作中可能用到的——点击时间短一种事件,时间长一种事件
- 【openjudge 8209】月度开销
- 数据结构-栈-顺序存储-基本运算
- 10月29日码神日志免费报名啦——实践开发者的社群理想
- 数据结构-双栈-顺序存储-基本运算
- poj2778 DNA Sequence