<p>Given a string <code>s</code>, return <code>true</code> <em>if it is possible to split the string</em> <code>s</code> <em>into three <strong>non-empty</strong> palindromic substrings. Otherwise, return </em><code>false</code>.​​​​​</p>

<p>A string is said to be palindrome if it the same string when reversed.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;abcbdd&quot;
<strong>Output:</strong> true
<strong>Explanation: </strong>&quot;abcbdd&quot; = &quot;a&quot; + &quot;bcb&quot; + &quot;dd&quot;, and all three substrings are palindromes.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;bcbddxy&quot;
<strong>Output:</strong> false
<strong>Explanation: </strong>s cannot be split into 3 palindromes.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>3 &lt;= s.length &lt;= 2000</code></li>
	<li><code>s</code>​​​​​​ consists only of lowercase English letters.</li>
</ul>

class Solution {
public:
    vector<vector<bool>> ispalind(string& s){
         vector<vector<bool>> dp(s.length(),vector<bool>(s.length(),false));
         for(int i=0;i<s.length();i++){
            dp[i][i]=true;
         }
         for(int i=0;i<s.length()-1;i++){
            if(s[i]==s[i+1])
                dp[i][i+1]=true;
         }
         for(int len=3;len<s.length();len++){
            for(int i=0;i<s.length()-len+1;i++){
                int j=i+len-1;
                if(s[i]==s[j] && dp[i+1][j-1]){
                    dp[i][j]=true;
                }
            }
         }
         return dp;
    }
    bool solve(string& s, int index, int cnt,vector<vector<bool>>& dp,vector<vector<int>>& dp1) {
        if (cnt>3) return false;
        if (index==s.length() && cnt==3) return true;
        if (index==s.length()) return false;
        if(dp1[index][cnt]!=-1) return dp1[index][cnt];

        for(int i=index;i<s.length();i++){
             if(cnt<=3 && dp[index][i]){
                if(solve(s,i+1,cnt+1,dp,dp1))
                    return dp[index][cnt]=true;
             }
        }
        return dp1[index][cnt]=false;
    }
    bool checkPartitioning(string s) {
        vector<vector<bool>> dp=ispalind(s);
        vector<vector<int>> dp1(s.length()+1,vector<int>(s.length()+1,-1));
        return solve(s,0,0,dp,dp1);
    }
};

147183