<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:
    vector<string> ans;

    void f(int depth,int i,int n,string s){
        if(i == n){
            if(depth == 0) ans.push_back(s);
            return;
        }

        s.push_back('(');
        f(depth+1,i+1,n,s);
        s.pop_back();
        if(depth){
            s.push_back(')');
            f(depth-1,i+1,n,s);
            s.pop_back();
        }
    }

    vector<string> generateParenthesis(int n) {
        f(0,0,2*n,"");
        return ans;    
    }
};

/*
if depth > 0 u can either open or close
at the end depth should be 0
if depth 0 only open
*/

23335