Dynamic Programming21 sections · 916 units
Open in Course

Core Concept

Range-based states

Interval DP (dynamic programming) solves problems where you need to find the optimal way to process a contiguous range. In interval DP, dp[i][j]dp[i][j] represents the answer for elements from index i to j.

The key difference from other DP: instead of building from smaller indices, you build from shorter ranges to longer ones. A range of length 11 is your base case. Then length 22, then 33, and so on. Why ranges? Some problems have this structure: the answer for [i,j][i,j] depends on how you split it into [i,k][i,k] and [k+1,j][k+1,j]. You try all split points kk and pick the best.