UVa 10898 - Combo Deal

10898 - Combo Deal

 * http://acm.uva.es/p/v108/10898.html

Summary
It's an optimization problem that deals with minimizing the cost given a set of items to purchase and combos that are cheaper than the individual items. Given the small constraints, the problem is easy to use dynamic programming to solve.

Explanation
Use Dynamic Programming on the (up to) six items. Since there can at most be 9 requests, that means the space we're searching is at most $$O(10^6)$$, definitely small enough.

Basically, the recurrence is simply:

$$Best( x_1, x_2, \ldots, x_6 ) = min( Best( x_1 - c_1, x_2 - c_2, \ldots, x_6 - c_6 ) + p )$$

where $$x_1, x_2, \ldots, x_6$$ are simply the items, $$c_1, c_2, \ldots, c_6$$ are the number of items in a given combo, and $$p$$ is the price of that given combo.

Implementations
Some can easily make it simplier by using a 6 digit decimal number - one for each item in the given function.

Input
4 349 99 109 219 2 1 1 1 0 479 2 2 2 1 999 2 9 6 8 0 9 6 8 5

Output
4139 4700