#include <iostream>
#include <vector>
using namespace std;
const int M = 8;
int n = 0;
bool check(vector<vector<bool> > &matrix, int row, int column) {
if (row == 0) {
return true;
}
int i, j;
for (i = 0; i < row; i++) {
if (matrix[i][column]) {
return false;
}
}
i = row - 1;
j = column - 1;
while (i >= 0 && j >= 0) {
if (matrix[i][j]) {
return false;
}
i--, j--;
}
i = row - 1;
j = column + 1;
while (i >= 0 && j < M) {
if (matrix[i][j]) {
return false;
}
i--, j++;
}
return true;
}
void output(vector<vector<bool> > &matrix) {
n++;
cout << "*********************************************" << endl;
for (int i = 0; i < M; i++) {
for (int j = 0; j < M; j++) {
cout << matrix[i][j] << " ";
}
cout << endl;
}
cout << "*********************************************" << endl;
}
void eightQueen(vector<vector<bool> > &matrix, int row) {
for (int column = 0; column < M; column++) {
matrix[row][column] = true;
if (check(matrix, row, column)) {
if (row + 1 == M) {
output(matrix);
} else {
eightQueen(matrix, row + 1);
}
}
matrix[row][column] = false;
}
}
int main() {
vector<vector<bool> > matrix(M, vector<bool>(M, false));
eightQueen(matrix, 0);
cout << n << "种解" << endl;
system("pause");
return 0;
}