dynamic prog. knapsack problem