This can easily be solved by the solution provided at WikiPedia (http://en.wikipedia.org/wiki/Knapsack_problem ).
Here is the pseudo code
// Input:
// Values (stored in array v)
// Weights (stored in array w)
// Number of distinct items (n)
// Knapsack capacity (W)
for j from 0 to W do
m[0, j] := 0
end for
for i from 1 to n do
for j from 0 to W do
if w[i] <= j then
m[i, j] := max(m[i-1, j], m[i-1, j-w[i]] + v[i])
else
m[i, j] := m[i-1, j]
end if
end for
end for
In your case
W(knapsack Capacity) = 50,
n(Number of distinct items) = 5
Now job is converting this pseudo-code to real working code i.e. that is your homework :)