<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>> ans;
    bool palindrom[20][20];
    string sub[20][20];
    bool cekPalin(string s){
        int len = (s.size()/2);
        int len2 = s.size();
        bool palin=true;
        for(int i=0;i<len;i++){
            if(s[i]!= s[len2-i-1]){
                palin = false;
                break;
            }
        }
        return palin;
    }
    void find(int head,int idx,vector<pair<int,int> > part,int end){
        if(idx == end){
            part.push_back(make_pair(head,idx));
            if(palindrom[head][idx]){
            
                int len = part.size();
                vector<string> temp;
                for(int i=0;i<len;i++){
                temp.push_back(sub[part[i].first][part[i].second]);
                
                }
                ans.push_back(temp);
            }
        }
        if(idx < end){
            find(head,idx+1,part,end);
        if(palindrom[head][idx]){
            
            part.push_back(make_pair(head,idx));
            
            find(idx+1,idx+1,part,end);
        }
        
        }
    }
    vector<vector<string>> partition(string s) {
        int len= s.size();
        for(int i=0;i<len;i++){
            for(int j=0;j<len-i;j++){
                palindrom[i][i+j] = cekPalin(s.substr(i,j+1));
                sub[i][i+j] = s.substr(i,j+1);
                // cout << sub[i][i+j] <<palindrom[i][i+j] << endl;
            }
        }
        vector<pair<int,int>> tes;
        find(0,0,tes,len-1);
        return ans;
    }
};
295448