<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 solve(int o,int c,vector<string>& ans,stack<char> stk,string curr){
        if(o==0 && c==0){
            if(stk.empty()){
                ans.push_back(curr);
            }
            return;
        }
        if(stk.empty()){
            if(o != 0){
                stk.push('(');
                solve(o-1,c,ans,stk,curr+"(");
            }
        }else{
             if(o != 0){
                stk.push('(');
                solve(o-1,c,ans,stk,curr+"(");
                stk.pop();
            }
            if(c!=0){
                if(stk.top()=='('){
                    stk.pop();
                    solve(o,c-1,ans,stk,curr+")");
                }
            }
        }
    }
    vector<string> generateParenthesis(int n) {
        vector<string> ans;
        stack<char> stk;
        solve(n,n,ans,stk,"");
        return ans;
    }
};
31233