要启动回溯算法,i=0 时可以调用以下伪代码;X[1..0] 表示空元组。
ALGORITHM Backtrack(X[1..i])
//Gives a template of a generic backtracking algorithm
//Input: X[1..i] specifies first i promising components of a solution.
//Output: Alll the tuples representing the problem's solutions
If X[1..i] is a solution write X[1..i]
else
for each element x belongs to Si+1 consistent with X[1..i] and constraints do
X[i+1] <- x
Backtrack(X[1..i+1])
我很难理解上述逻辑。我试图通过逐步解决 4 皇后问题,但没有。请通过 4 个皇后问题的步骤帮助您理解上述逻辑。
谢谢!