Leetcode 1745. Palindrome string segmentation IV (DAY 67) ---- Dynamic programming learning period (I feel that this type of problem is not difficult for me to win the second question)

Original title

Insert picture description here


Code implementation (first brush self-solving)

class Solution {
    
    
public:
    bool checkPartitioning(string s) {
    
    
        int strl = s.size(),end,start;
        vector<vector<int>> dp(strl,vector<int>(strl,0));
        for(end = 0;end<strl;end++)
        {
    
    
            for(start=end;start>=0;start--)
            {
    
    
                if(s[start] == s[end])
                {
    
    
                    if(end <= start+2  || dp[start+1][end-1])
                        dp[start][end] = 1;
                }
            }
        }

        for(start=0;start<=strl-3;start++)
        {
    
    
            for(end=start+1;end<=strl-2;end++)
            {
    
    
                if(dp[0][start] && dp[start+1][end] && dp[end+1][strl-1])
                    return true;
            }
        }
        return false;
    }
};

Guess you like

Origin blog.csdn.net/qq_37500516/article/details/115114568