<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 dp2[2000][2000];
    int helper(string &ans,int i,int j)
    {
        // int i=0;
        // int j=ans.length()-1;
        // int count=0;
        if(i>=j)
        {
            return 1;
        }
        if(dp2[i][j]!=-1)
        {
            return dp2[i][j];
        }
        if(ans[i]==ans[j])
        {
            return dp2[i][j]=helper(ans,i+1,j-1);
        }
        return dp2[i][j]=false;
    }
    int dp[2005][5];
    bool help(string &s,int i,int l)
    {
        int k=3;
        if(l>3)
        {
            return 0;
        }
        if(i==s.length())
        {
            if(l==3)
            {
                // cout<<ans<<endl;
                return 1;
            }
            return 0;
        }
        if(dp[i][l]!=-1)
        {
            return dp[i][l];
        }
        int n=s.length();
        string ans;
        bool a=false;
        for(int x=i;x<n;x++)
        {
            ans+=s[x];
            if(helper(s,i,x)==0)
            {
                continue;
            }
            // cout<<ans<<endl;
            int lm=help(s,x+1,l+1);
            if(lm)
            {
                // cout<<ans<<endl;
                return dp[i][l]=true;
            }
        }
        return dp[i][l]=a;
    }
    bool checkPartitioning(string &s) {
        memset(dp,-1,sizeof(dp));
        memset(dp2,-1,sizeof(dp2));
        if(s.length()==3)
        {
            return 1;
        }
        return help(s,0,0);
    }
};
70458