<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>

class Solution {
public:

    void generate(int n, int open, int close, string str, vector<string>& list) {
        if(open == n && close == n) {
            list.push_back(str);
            return;
        }
        if(open <= n && close < open) {
            string str1 = str;
            str1.push_back('(');
            generate(n, open+1, close, str1, list);
            string str2 = str;
            str2.push_back(')');
            generate(n, open, close+1, str2, list);
        }
        if(open <= n && close == open) {
            string str1 = str;
            str1.push_back('(');
            generate(n, open+1, close, str1, list);
        }
    }

    vector<string> generateParenthesis(int n) {
        vector<string> list;
        string str = "(";
        int open = 1, close = 0;

        generate(n, open, close, str, list);

        return list;
    }
};
16956