SPOJ PARTY

97 (PARTY) - Party Schedule

 * https://www.spoj.pl/problems/PARTY/

Summary
This is the classic 0-1 Knapsack problem, which can be handled by dynamic programming. Note that the maximum amount of budget and number of parties are given so that you know the maximum size of dynamic programming array.

Consider $$A_{ij}$$ = maximum fun we can get from the budget of i and consider only first j party in the list (the solution is clearly $$A_{mn}$$ where m is the given budget and n is the number of parties

$$A_{0j} = 0 \quad \forall j$$

$$A_{i0} = 0 \quad \forall i$$

If $$i < cost[j]$$ then

$$A_{ij} = A_{(i)(j-1)}$$

otherwise

$$A_{ij} = \max(A_{(i)(j-1)}, A_{(i-cost[j])(j-1)} + fun[j])$$

Explanation
Explanation of the ideas behind the solution goes here.

Gotchas

 * Any points one can easily overlook?
 * The correct way to understand ambiguous formulations?

Implementations
Notes/Hints on actual implementation here.

Optimizations
Optimizations here.

Input
Input Here

Output
Output Here