Is there any package that implements Dynamic Programming like maximises/minizises the sum or product in a three way matrix in R?Like the problem that i have solved by hand (attached pdf file)