Pergunta de entrevista da empresa A9.com

I misunderstood a question on Dyanamic Programming but figured it out later on.