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
50 10 12 3 15 8 16 9 16 6 10 2 21 9 18 4 12 4 17 8 18 9

50 10 13 8 19 10 16 8 12 9 10 2 12 8 13 5 15 5 11 7 16 2

0 0

Output
49 26 48 32

Solutions
F#: [http://adilakhter.wordpress.com/2013/02/16/spoj-97-party-schedule-party-with-f/ SPOJ 97. Party Schedule (PARTY) with F#]