<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:
int palin(int i,int j,string &s){
        while(i<j){
            if(s[i]!=s[j])return 0;;
            i++;
            j--;
        }
        return 1;
    }
    int solve(int i,int j,string &s,int k,vector<vector<int>>& dp){
        if(j==(k-1)){
            return palin(i,s.size()-1,s);
        }
        if(dp[i][j]!=-1)return dp[i][j];
        int ans=0;
        int l=min(s.size(),(s.size()-(k-j)));
        for(int ind=i;ind<=l;ind++){
            if(palin(i,ind,s))
                ans=ans|solve(ind+1,j+1,s,k,dp);
        }
        return dp[i][j]=ans;
    }
    bool checkPartitioning(string s) {
        vector<vector<int>>dp(s.size(),vector<int>(3,-1));
        return solve(0,0,s,3,dp);
    }
};
11636