Dynamic Programming in bag problem