/* 自定義代碼塊樣式 */

herrDeng網內搜尋

自訂搜尋

Ads

2026年7月2日 星期四

LeetCode 3286: 別只用 Dijkstra!0-1 BFS (deque) 才是 0ms 關鍵


0ms |C++ Py3| BFS使用deque解Leetcode 3286  Find a Safe Walk Through a Grid
了解以下幾點有助於解決最短路徑問題:
所有權重相同時,只需使用基於佇列queue的廣度優先搜尋(BFS over queue)
權重有兩種非負值(如本題所示),使用基於雙端佇列(deque)的廣度優先搜尋(BFS over deque)
權重為正值時,使用基於優先權佇列(priority queue)的廣度優先搜尋(類似Dijkstra演算法)
----
It's good to know: To solve the shortes path problem
all weights are same, just use BFS over queue
2 kinds of non-negative weights, like in this question, use BFS over deque
different positive weights, BFS over priority queue (Dijkstra-like)

沒有留言:

Related Posts Plugin for WordPress, Blogger...

熱門文章