回溯法,代码如下:
/**
* author Akalius Kung 2008-2-8
**/
public class Queen {
private int[] grids; // location in each row, index is each row, array value is location of each queen
private int n;
private static int sum;
public Queen() {
init(8);
}
public Queen(int n) {
this.n = n;
grids=new int[n];
for(int i=0;i<n;i++){
grids[i]=0;
}
}
private void init(int n){
...