Technique
Knuth's Optimisation
For interval DP dp[i][j] = min_k dp[i][k] + dp[k+1][j] + C(i, j) where opt(i, j-1) <= opt(i, j) <= opt(i+1, j), restrict k to that window for O(n2).
Learn firstInterval DP
0%
mastery
0/1 solved
0/1 solved
Recognise it
The signal
merge/split costs on a line (optimal BST, stick cutting, file merging)
1Brute force
O(n3) interval DP.
2The observation
Scanning all splits: the optimal split is monotone in both endpoints.
3Why it works
opt(i, j-1) <= opt(i, j) <= opt(i+1, j).
Reach for it when
- +C satisfies quadrangle inequality and monotonicity
Not when
- ×cost violates the conditions (verify or stress test)
Practice
0/1 solved
- Knuth DivisionCSESHard
Pitfalls
Misconceptions
- !applying it to burst-balloons-style DPs whose structure differs