Dynamic Programming21 sections · 916 units
Open in Course

Pattern - Interval DP

When to use it

Use interval DP when: the problem involves a contiguous range, the answer depends on how you split or process the range, and answers for smaller ranges help build larger ones.

Common signals: "minimum/maximum cost to process array", "optimal way to merge/split", "number of ways to parenthesize". The template: dp[i][j]dp[i][j] for range, iterate by length, try all split points, combine answers from smaller ranges. Time is usually O(n3)O(n^3).