How can I implement dynamic programming algorithm on this question? There is dynamic programming tag in this question