<p>Given <code>n</code> pairs of parentheses, write a function to <em>generate all combinations of well-formed parentheses</em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> n = 3
<strong>Output:</strong> ["((()))","(()())","(())()","()(())","()()()"]
</pre><p><strong class="example">Example 2:</strong></p>
<pre><strong>Input:</strong> n = 1
<strong>Output:</strong> ["()"]
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= n &lt;= 8</code></li>
</ul>

static const auto _____ = []()
{
    // fast IO code : this I understand
    ios::sync_with_stdio(false);
    cin.tie(0);
    return 0;
}();

class Solution {
public:
    string test;
    vector<string> res;

    void gen(int open, int close, int i)
    {
        if (open > 0) {
            test[i] = '(';
            if (i < test.size() - 1) gen(open-1, close, i + 1);
            else res.push_back(test);
        }
        if (close - 1 >= open) {
            test[i] = ')';
            if (i < test.size() - 1) gen(open, close-1, i + 1);
            else res.push_back(test);
        }
    }

    vector<string> generateParenthesis(int n) {
        res = {};
        test.resize(n*2, 0);
        test[0] = '(';
        gen(n-1, n, 1);
        return res;
    }
};
9059