Pregunta de entrevista de Google

A question on dynamic programming.