<p>Given a string <code>s</code>, partition <code>s</code> such that every <span data-keyword="substring-nonempty">substring</span> of the partition is a <span data-keyword="palindrome-string">palindrome</span>.</p>

<p>Return <em>the <strong>minimum</strong> cuts needed for a palindrome partitioning of</em> <code>s</code>.</p>

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

<pre>
<strong>Input:</strong> s = &quot;aab&quot;
<strong>Output:</strong> 1
<strong>Explanation:</strong> The palindrome partitioning [&quot;aa&quot;,&quot;b&quot;] could be produced using 1 cut.
</pre>

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

<pre>
<strong>Input:</strong> s = &quot;a&quot;
<strong>Output:</strong> 0
</pre>

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

<pre>
<strong>Input:</strong> s = &quot;ab&quot;
<strong>Output:</strong> 1
</pre>

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

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

int pdp[2004][2004];
int dp[2004];
class Solution {
public:
    int func(int idx, vector<int>adj[], int n)
    {
        if(idx==n)
        return 0;
        if(dp[idx]!=-1)
        return dp[idx];
        int res=1e9;
        for(auto &x: adj[idx])
        {
            res=min(res, 1+func(x+1, adj, n));
        }
        return dp[idx]=res;
    }
    int minCut(string s) {
        memset(dp, -1, sizeof(dp));
        int n=s.size();
        for(int g=0; g<=n; g++)
        {
            for(int i=0, j=g; j<n; i++, j++)
            {
                if(g==0)
                {
                    pdp[i][j]=1;
                }
                else if(g==1)
                {
                    pdp[i][j]=(s[i]==s[j]);
                }
                else
                {
                    if(pdp[i+1][j-1] && (s[i]==s[j]))
                    pdp[i][j]=1;
                    else
                    pdp[i][j]=0;
                }
            }
        }
        vector<int> adj[n];
        for(int i=0; i<n; i++)
        {
            for(int j=i; j<n; j++)
            {
                if(pdp[i][j])
                adj[i].push_back(j);
            }
        }
        int res=func(0, adj, n);
        return res-1;
    }
};
53734