DP solution to the knapsack problem