Suppose I have array of positive integers, each standing for a length of a rod, e.g.:
[26, 103, 59]
I want to find some positive integer size into which I will cut each of these rods. I will be penalized by the total number of cuts I make and by the sum of the remainders.
Example
For example, if I cut the rods whose lengths are as above, into pieces of length 6, I will get:
rod one (length 26): 4 pieces + remainder 2
rod two (length 103): 17 pieces + remainder 1
rod three (length 59): 9 pieces + remainder 5
The penalties are
4 + 17 + 9 = 30 cuts
2 + 1 + 5 = 8 remainder
I'd like an algorithm taking as inputs:
an array of rod lengths
a cut-penalty cost
a remainder-penalty cost
and outputting the optimal cut size.