DP: Knapsack problem (2 implementations)