N皇后问题

// Created by ljs on 2018/8/27.
//
#include 
using namespace std;
#define MAX 100
int cols[MAX];

bool isValid(int n, int cur, int row){
    if(cur >= n || cur < 0) return false;
    for(int i = 0; i < cur; i++){
        if(cols[i] == row || abs(cols[i] - row) == (cur - i)) return false;
    }
    return true;
}

void Solve(int cur, int n, int& flag){
    //cout<<"cur "<>t;
    while(t--){
        cin>>n;
        int flag = 0;
        Solve(0, n , flag);
        if(!flag) cout<<-1;
        cout<

你可能感兴趣的:(N皇后问题)