KnapSack dynamic programming in R with recursive function