public class EightQueue {
List<int[][]> datas = new ArrayList<>();
static int count = 0;
public static void main(String[] args) {
int[][] queue = new int[8][8];
putColumn(queue, 0);
System.out.println(count);
}
private static void putColumn(int[][] queue, int column) {
if (column >= queue.length) {
count++;
return;
}
for (int j = 0; j < queue[column].length; j++) {
if (canPut(queue, column, j)) {
queue[column][j] = 1;
putColumn(queue, column + 1);
queue[column][j] = 0;
}
}
}
private static boolean canPut(int[][] board, int row, int col) {
int n = 8;
for (int i = 0; i < n; i++) {
if (board[i][col] == 1)
return false;
}
for (int i = row - 1, j = col + 1;
i >= 0 && j < n; i--, j++) {
if (board[i][j] == 1)
return false;
}
for (int i = row - 1, j = col - 1;
i >= 0 && j >= 0; i--, j--) {
if (board[i][j] == 1)
return false;
}
return true;
}
}