1
votes

I recently heard a question that was a variation of the cutting rods problem.

If you have rods of length 10, and you get an orders from customers for various size rods (ie one customer orders a rod of length 4, another length 7, another length 6), how many rods do you need to minimize loss?

I've been trying to think of a solution for this for a while, but I can't come up with a convincing solution.

Thank you!

edit:

You are given an array of all of the orders. For instance, [4,8,9,1,4,3,7]. The length of the rod is 10 (hence each of the orders have to be less than 10).

1

1 Answers

1
votes

Unless I'm missing some detail about what "minimize loss" in the question means, this problem seem to be in the same form as the bin packing problem, which is NP-hard.

There seems to be some dynamic programming solutions to the problem, seemingly faster than brute force, but still not very impressive. As can be seen on Wikipedia, there are fairly quick, exact algorithms available (non-polynomial, of course).