using DP to solve this issue.