<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:
    void palindrome_dp(string& s,vector<vector<bool>>& dp)
    {
        int i,j,n=s.size(),len;
        for(i=0;i<n;i++) dp[i][i]=true;

        for(len=2;len<=n;len++)
        {
            for(i=0;i<n-len+1;i++){
                j=i+len-1;
                if(s[i]==s[j])
                {
                    if(len==2) dp[i][j]=true;
                    else{
                        dp[i][j]=dp[i+1][j-1];
                    }
                }
            }
        }
    }

    bool checkPartitioning(string s) 
    {
        int n = s.size(),end,start,i,j;
        vector<vector<bool>> isPalindrome(n,vector<bool>(n,false));
        palindrome_dp(s,isPalindrome);

        vector<vector<bool>> dp(n,vector<bool>(n,false));

        dp[0][1]=true;
        for(end=1;end<n-1;end++){
            for(start=0;start<=end;start++)
            {
                if(isPalindrome[start][end])
                {
                    // if(start==0) len1 ko 1 krdo, nhi to len 2 ke liye check kar lo, agar zero hai to zero hi rehne de
                    if(start==0){
                        dp[end][1]=true;
                    }
                    else{
                        if(dp[start-1][1]) dp[end][2]=true;
                    }
                }
            }
        }

        for(start=1;start<n;start++){
            if(isPalindrome[start][end]){
                if(dp[start-1][2]) return true;
            }
        }
        return false;
    }
};
32096