Overview
Partition DP (Interval DP) is used when the problem can be broken down into sub-problems spanning contiguous intervals `[i, j]`.
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
Learn how to solve problems where you evaluate every possible sub-interval (partition) of an array by iterating over its length.
Partition DP (Interval DP) is used when the problem can be broken down into sub-problems spanning contiguous intervals `[i, j]`.
We process intervals in increasing order of their length. This guarantees that when solving `[i, j]`, all smaller intervals inside it are already solved.
For a fixed interval `[i, j]`, we try every possible split point `k`. The cost is usually the cost of the left side, the right side, plus the cost to combine them.
The 3 nested loops (length `len`, start `i`, and split `k`) give the classic O(N^3) time complexity. Memory is a 2D table `dp[i][j]`.