Which techniques solve the rod-cutting problem using dynamic programming?
Exercise
- Memoize the best revenue for each length
- Consider all cut lengths and choose the best cuts
- Greedily take the shortest length first
- Tabulate the maximum revenue for every length
- Enumerate every complete cutting pattern
- Minimize the number of cuts attaining the best revenue
Solution
Options 1 and 4 store optimal subproblem values. Option 2 gives the transition when each first cut is combined with the saved optimum for the remaining length.
R(0) = 0
R(n) = max{pᵢ + R(n − i) : 1 ≤ i ≤ n}
After choosing an initial piece of length i, a rod of length n−i remains. Add the best revenue for that remainder, which may itself need cutting, to the first piece's price. A cache or a table avoids solving the same remainder again.
p₁ = 2, p₂ = 5, p₃ = 6, p₄ = 8. R(1) = 2, R(2) = 5, R(3) = 7. R(4) = max(2+7, 5+5, 6+2, 8+0) = 10.
In the numerical example two pieces of length two are best. A single uncut piece of length four sells for eight, while the optimal cut gives ten.
Platforms
- MAXIMUM
