dynamic programming

how to solve this problem?