Overview
This is a classic Interval DP problem. Just like Matrix Chain Multiplication, the cost depends on which cut you make first (i.e. where you split the interval).
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
Given a stick of length n and an array of cuts, find the minimum cost to perform all cuts where the cost of a cut is the length of the current stick.
This is a classic Interval DP problem. Just like Matrix Chain Multiplication, the cost depends on which cut you make first (i.e. where you split the interval).
To easily calculate stick lengths, we add the boundaries `0` and `n` to the cuts array and sort it. Now, cuts become interval boundaries.
If we cut interval `[i, j]` at point `k`, the cost is the cost to cut the left piece `[i, k]` plus the right piece `[k, j]`, plus the length of the current stick `cuts[j] - cuts[i]`.
We process intervals by length, starting from length 2 (which means 1 cut in between). A length of 1 means no cuts are between `i` and `j`, so the cost is 0.
| I=0 | 0 | 0 | 0 | 0 |
| I=1 | 0 | 0 | 0 | 0 |
| I=2 | 0 | 0 | 0 | 0 |
| I=3 | 0 | 0 | 0 | 0 |