ayit 2n 皇后
来源:互联网 发布:模拟q币充值软件 编辑:程序博客网 时间:2024/04/30 01:46
http://ayit.acmclub.com/index.php?app=problem_title&id=233&problem_id=21436
一行一行的枚举,先枚举第一行,然后枚举每一列,在枚举的列的时候对行进行深搜。
#include<iostream>#include<cstdio>using namespace std;int n,count=0,map[10][10],vis[10][10];bool check(int x,int y,int color){ int i ,j; for(i = 1; i <= x; i++) if(vis[i][y] == color) return false; for(i = x,j = y; i>0 && j>0;i--,j--) if(vis[i][j] == color) return false; for(i = x,j = y; i>0 && j<= n;i--,j++) if(vis[i][j] == color) return false; return true;}void dfs(int i){ int j,k; if(i > n) {count++;return;} for(j = 1; j <= n; j++) { if(map[i][j] == 1 && check(i,j,1)) { vis[i][j] = 1; for(k = 1; k <= n; k++) { if(j!= k&&map[i][k] == 1 && check(i,k,-1)) { vis[i][k] = -1; dfs(i+1); vis[i][k] = 0; } } vis[i][j] = 0; } }}int main(){ int i,j; cin>>n; for(i = 1; i <= n; i++) for(j = 1; j <= n; j++) cin>>map[i][j]; dfs(1); cout<<count<<endl; return 0;}
0 0
- ayit 2n 皇后
- n皇后,2n皇后
- 2n皇后问题
- 2n皇后问题
- 蓝桥杯 2n皇后
- 2n皇后
- 2n皇后问题
- 2n皇后问题
- 2n皇后问题
- 2N皇后
- 2n皇后问题
- 2N皇后问题
- 2n皇后问题
- 2n皇后问题
- 蓝桥杯--2N皇后
- 2n皇后问题
- 2n皇后问题
- 2n皇后问题
- 图片加载缓存+双指拉伸图片实战
- 控制台显示 Unicode中文
- NGUI深入理解-----------------UIRoot
- JQuery入门
- NYOJ 16 矩形嵌套
- ayit 2n 皇后
- 蓝桥杯——罗马数字
- Win8各国语言包的安装,让系统变成你想要的语言版,带你体验不一样的输入法
- 第一个flash builder webgis应用程序
- 我的IT成长路
- IOC和AOP
- SIP参考大全
- mysql 数据分页显示
- Mybatis 异常: The content of elements must consist of well-formed character data or markup