Dynamic Programming21 sections · 916 units
Open in Course

What's Next

Preview of Monotonic Queue

CHT optimizes DP with linear cost functions. But some DPs have range constraints: jj must be within a sliding window of ii. Monotonic Queue improvement handles dp[i]=minj[ik,i1](dp[j])+cost(i)dp[i] = \min_{j \in [i-k, i-1]}(dp[j]) + cost(i). The valid jj range slides with ii.

Instead of a hull of lines, we maintain a deque of values. The front is always the best in the current window. Both are deque-based optimizations, but for different DP structures. Learn both to cover more problem types.