Technique
Divide & Conquer DP Optimisation
For dp[i][j] = min_k dp[i-1][k] + C(k, j) with opt(i, j) non-decreasing in j, compute each row by recursing on the middle j with a narrowed k range.
0%
mastery
0/2 solved
0/2 solved
Recognise it
The signal
split an array into K groups minimising sum of group costs
1Brute force
Try every k for every (i, j): O(K n2).
2The observation
Scanning all split points: monotone opt bounds the search range.
3Why it works
opt(i, j) <= opt(i, j+1).
Reach for it when
- +cost satisfies the quadrangle inequality
Not when
- ×opt not monotone
- ×1D recurrence with linear cost (cht may be better)
Practice
0/2 solved
- Subarray SquaresCSESHard
- Houses and SchoolsCSESHard
Pitfalls
Misconceptions
- !assuming monotonicity without checking the quadrangle inequality
Go deeper1 combinations · resources
Combinations
Divide & Conquer DP Optimisation+Prefix Sum
split array into k parts minimising sum of squared/segment costs
- Divide & Conquer DP Optimisation:
- monotone split points per layer
- Prefix Sum:
- O(1) segment cost