Basic example
Input
rod_cut([1,5,8,9], 4)
Output
10
For a rod of length 4 with prices [1,5,8,9], cutting into two pieces of length 2 each (price 5 + 5) yields 10, which is maximum.
Full lesson preview
Given prices for rod pieces, compute the maximum revenue obtainable by cutting a rod into integer lengths using dynamic programming.
Problem statement
Task
Examples
Input
rod_cut([1,5,8,9], 4)
Output
10
For a rod of length 4 with prices [1,5,8,9], cutting into two pieces of length 2 each (price 5 + 5) yields 10, which is maximum.
Input format
Output format
Constraints
Samples
Input
rod_cut([2,5,7,3,9], 5)
Output
12
Best is to cut into lengths 2 and 3 (5 + 7 = 12).