Pregunta de entrevista de Duco

It was a 2-dimensional dynamic programming question.