Can someone help me to understanding and solving this dynamic programming question , I am completely stuck