首页 > 其他 > 详细

八皇后

时间:2019-11-09 22:17:54      阅读:50      评论:0      收藏:0      [点我收藏+]
#include <iostream>

using namespace std;
const int maxn=100;

int n,P[maxn],hashTable[maxn]={false};

void generateP(int index){
    if(index == n+1){
        count++;
        return;
    }
    for(int x=1;x<=n;x++){
        if(hashTable[x]==false){
            bool flag=true;
            for(int pre=1;pre<index;pre++){
                if(abs(index -pre)==abx(x-P[pre])){
                    flag=false;
                    break;
                }
            }
            if(flag){
                P[index]=x;
                hashTable[x]=true;
                generateP(index+1);
                hashTable[x]=false;
            }
        }
    }
}

n皇后解决方案

八皇后

原文:https://www.cnblogs.com/King-boy/p/11827976.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!