Javaバージョンの反復バックトラッキングアルゴリズムと再帰バックトラッキングアルゴリズム



Java Version Iterative Backtracking Algorithm



バックトラッキング方式のアルゴリズムを終了した後、将来これらのアルゴリズムを忘れないようにするために、参考のために自分で気づきました。コードは次のとおりです。

package ctong import java.util.Random public class NQueen { /** * ctong */ / / Feasible solution array, starting from X [1] private static int[] X //The length of the X array private static int nn / / Record the number of feasible solutions private static int sum=0 /** * Iterative Algorithms */ public void iteration(int n){ int k=1 while(k>0){ X[k]++ while(X[k]