public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("1111");
placeQueens(8);
}
static int[] cols;
static int way = 0;
static void placeQueens(int n) {
cols = new int[n];
place(0);
System.out.println("一共有:"+way);
}
static void place(int row) {
if(row == cols.length) {
way++;
return;
}
for (int col = 0; col < cols.length; col++) {
if(isVa(row,col)) {
cols[row] = col;
place(row + 1);
}
};
}
static boolean isVa(int row,int col) {
for (int i = 0; i < row; i++) {
if(col == cols[i]) return false;
if (row - i == Math.abs(col - cols[i])) return false;
}
return true;
}
}