I’m trying to put together a system to suggest consumable kits based on a requested quantity. The challenge I’m running into is that the kits have volume/bulk discounts, so it may be cheaper for the customer to order a larger quantity because the price may be less. For example, let’s say the available kits are:
- 25 widgets for $15
- 10 widgets for $7
- 5 widgets for $4
- 1 widget for $1
Right now, for a requested quantity of 74, my algorithm will suggest 2 x 25, 2 x 10, and 4 x 1 = $48. It would be cheaper however for the customer to just order 3 x 25 = $45.
Any thoughts on how to tackle this? I’m coding in C#.
Thanks!
That looks like standard DP (dynamic programming).
The answer is
min(bestPrice[74], bestPrice[74 + 1], ... bestPrice[74 + 25 - 1]). Overhead25 - 1is obviously enough, because otherwise you would remove one pack and amount would still be>= 74.Some links on the topic:
http://en.wikipedia.org/wiki/Dynamic_programming
http://www.topcoder.com/tc?module=Static&d1=tutorials&d2=dynProg
edit
You can find optimal solution if you modify it a little. Add
lastPackarray, solastPack[i]is the size of the package you used to achieve amounti. I guess, you can figure out how to update pseudo-code above.Once algorithm is finished, you can get solution like this