DP

leetcode 132:
The key of dp problem is definition of state and inference of the relationship.
In this problem, we define dp[i] meaning the minimum cut from i to the end.
then the resolution is

 for (int i = len-1;i >= 0; --i){
            for (int j = i;j < len;++j){
                if ((s[i]==s[j] && j-i<2) || (s[i]==s[j]&&vis[i+1][j-1])){
                    vis[i][j] = true;
                    dp[i] = min(dp[i], dp[j+1]+1);
                }
            }
        }

you should also handle the problem of check whether the substring is palindrome or not. However, it’s not the concern in the article. So it’s just ignored.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325518833&siteId=291194637
DP