Leetcode Biweekly D

Can someone please share how do you use DP on this? Also how does one decide that this is a DP problem.