八皇后问题详细思路分析

八皇后问题详细思路分析_第1张图片

八皇后问题详细思路分析_第2张图片

package com.recursion;

public class Queue8 {

	//定义一个max表示共有多少个皇后
	int max = 8;
	//定义数组array,用于保存皇后放置位置的结果,比如arr = {0,4,7,5,2,6,1,3}
	int[] array = new int[max];
	static int count = 0;  //共多少解法
	public static void main(String[] args) {
	
		
		//测试
		Queue8 queue8 = new Queue8();
		queue8.check(0);
		
		System.out.println("一共有"+count+"解法");
	}
	
	//编写一个方法,放置第n个皇后
	//特别主意:check 是每一次递归时,进入到check中都有for(int i = 0;i

 

你可能感兴趣的:(八皇后问题详细思路分析)