0-1 knapsack problem with dynamic programming