UVa 10910 - Marks Distribution

10910 - Marks Distribution

 * http://acm.uva.es/p/v109/10910.html

Summary
A Dynamic Programming counting problem. Solve the problem by counting it with its subproblems.

Explanation
$$F(N,T,P)$$ can be defined recursively:

$$F(N,T,P) = \Sigma_{i=p}^{T-(N*P)+P}{ F( N - 1, T - i, P ) }$$ and $$F(0,0,P) = 1$$ which basically just states that the number of ways we can have N objects that sum up to T and up to minimum P is just the summation of the number of ways that having the number i as the current number, and the subproblem of N-1 objects that sums up to T-i, still with a minimum P.

Optimizations
Memoization is fine, and this problem can be solved bottom-up.

Input
3 3 34 10 3 34 10 7 50 2

Output
15 15 5245786