How to solve this problem. Can anyone give me any hint? I am new to the concept of dynamic programming questions.