mirror of
https://github.com/krahets/hello-algo.git
synced 2026-07-22 19:36:06 +00:00
build
This commit is contained in:
@@ -26,7 +26,7 @@ comments: true
|
||||
|
||||
也就是說,我們可以採取逐行放置策略:從第一行開始,在每行放置一個皇后,直至最後一行結束。
|
||||
|
||||
圖 13-17 所示為 $4$ 皇后問題的逐行放置過程。受畫幅限制,圖 13-17 僅展開了第一行的其中一個搜尋分支,並且將不滿足列約束和對角線約束的方案都進行了剪枝。
|
||||
圖 13-17 所示為 4 皇后問題的逐行放置過程。受畫幅限制,圖 13-17 僅展開了第一行的其中一個搜尋分支,並且將不滿足列約束和對角線約束的方案都進行了剪枝。
|
||||
|
||||
{ class="animation-figure" }
|
||||
|
||||
@@ -269,6 +269,7 @@ comments: true
|
||||
|
||||
}
|
||||
*res = append(*res, newState)
|
||||
return
|
||||
}
|
||||
// 走訪所有列
|
||||
for col := 0; col < n; col++ {
|
||||
|
||||
@@ -724,7 +724,7 @@ comments: true
|
||||
(*selected)[i] = true
|
||||
*state = append(*state, choice)
|
||||
// 進行下一輪選擇
|
||||
backtrackI(state, choices, selected, res)
|
||||
backtrackII(state, choices, selected, res)
|
||||
// 回退:撤銷選擇,恢復到之前的狀態
|
||||
(*selected)[i] = false
|
||||
*state = (*state)[:len(*state)-1]
|
||||
|
||||
Reference in New Issue
Block a user