← All questions
RareProgramming

Which techniques solve the rod-cutting problem using dynamic programming?

Short answer
Memoize the best revenue for each length · Tabulate the maximum revenue for every length

Exercise

  1. Memoize the best revenue for each length
  2. Consider all cut lengths and choose the best cuts
  3. Greedily take the shortest length first
  4. Tabulate the maximum revenue for every length
  5. Enumerate every complete cutting pattern
  6. 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.

Dynamic programming

Platforms

  • MAXIMUM

Download now and try it for free on your own tasks!

10 15 free credits • No credit card required
Version: Loading…

Choose the Windows app or the Chrome extension with phone controls.