[R] Dynamic Programming to deal with the Knapsack problem