<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 isPalindrome(string &s) {
        int l = 0, r = s.size() - 1;
        while(r > l) {
            if(s[r--] != s[l++]) return false;
        }
        return true;
    }
    void solve(string &s, int idx, int end, vector<string> &res) {
        if(idx >= s.size()) {
            ans.push_back(res);
            return;
        }
        if(end >= s.size()) {
            return;
        }
        // choose palindrome
        string s2 = s.substr(idx, end - idx + 1);
        //cout << s2 << endl;
        if(isPalindrome(s2)) {
            res.push_back(s2);
            solve(s, end + 1, end + 1, res);
            res.pop_back();
        } 
        // for larger range
        solve(s, idx, end + 1, res);
        // one character
        // res.push_back(s.substr(idx, 1));
        // solve(s, idx + 1, end + 1, res);
    }
    vector<vector<string>> partition(string s) {
        vector<string> res;
        solve(s, 0, 0, res);
        return ans;
    }
}; 
97900