回溯法-n皇后
来源:互联网 发布:淘宝网商城女装春装 编辑:程序博客网 时间:2024/05/17 23:54
#include<iostream>using namespace std;int legal(int i,int j,int a[][4]){int cn = 0;for(int row = 0;row<=i;row++){if(a[row][j]!=0)cn++;}if(cn>=2){return 0;}return 1;}int Trial(int i,int n,int a[][4]){if(i>=n){for(int row = 0;row<n;row++){for(int col = 0;col<n;col++)if(a[row][col]!=0)cout<<col;}cout<<endl;return 1;}elsefor(int j = 0;j<n;j++){a[i][j] = 1;if(legal(i,j,a)){Trial(i+1,n,a);}a[i][j] = 0;//回溯重要的标志}}int main(void){int a[4][4]={0};for(int row = 0;row<4;row++){for(int col = 0;col<4;col++)cout<<a[row][col];cout<<endl;}Trial(0,4,a);return 0;}
0 0
- 回溯法-n皇后
- n皇后问题-回溯法
- 回溯法求解n皇后
- 【回溯法】n皇后问题
- N皇后问题,回溯法
- 回溯法---n皇后问题
- N皇后问题 【回溯法】
- 【回溯法】n皇后问题
- HDU2553 - n皇后(回溯法)
- N皇后问题---回溯法
- N 皇后问题-回溯法
- N皇后问题--回溯法
- 回溯法.N皇后问题
- N皇后问题 回溯法
- 回溯法解决N皇后问题
- 从N-皇后问题看回溯法
- 回溯法-求n皇后问题
- 回溯法求解n皇后问题
- 反码补码
- Python学习笔记(二)
- JS获取当前页、上一页及域名
- stata随笔(1)
- [c++]抽象类
- 回溯法-n皇后
- css3-animation动画
- java 避免显示null 字符的
- Socket TCP Ping使用小结
- 从Excel中复制数据
- Eclipse使用技巧。
- httpclient 4.3.1 post get的工具类
- iOS自定义字体及类目
- JavaIo学习Properties