<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"><strong>palindrome</strong></span>. Return <em>all possible palindrome partitioning of </em><code>s</code>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> s = "aab"
<strong>Output:</strong> [["a","a","b"],["aa","b"]]
</pre><p><strong class="example">Example 2:</strong></p>
<pre><strong>Input:</strong> s = "a"
<strong>Output:</strong> [["a"]]
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= s.length &lt;= 16</code></li>
	<li><code>s</code> contains only lowercase English letters.</li>
</ul>

class Solution {
public:
    vector<vector<string>>v;
    void T(vector<string>&temp,int i, string s,
    vector<vector<bool>>dp, int n ){
        if (i>=n){
            v.push_back(temp);
            return;
        }
        for (int ind = i; ind<n; ind++){
            if (dp[i][ind]){
                string tempo = s.substr(i,ind-i+1);
                temp.push_back(tempo);
                T(temp,ind+1,s,dp,n);
                temp.pop_back();
            }

        }
        return;
    }

    vector<vector<string>> partition(string s) {
        int n = s.size();
        vector<vector<bool>>dp(n+1,vector<bool>(n+1,0));
        for (int i=0; i<n; i++){
            for (int j=0; j<=i; j++){
                if (i==j){
                    dp[j][i]= 1;
                }
                else if (i-j==1 && s[i]==s[j]){
                    dp[j][i]=1;
                }
                else if (s[i]==s[j]){
                    dp[j][i]= dp[j+1][i-1];
                }
            }
        }
        vector<string>nnn;
        T(nnn,0,s,dp,n);
        return v;


    }
};
298634