Dynamic Programming method

Good Solution.