Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- int n;
- vector<char>arr(0);
- void gen(int ind, int open){ // open : [ cnt of '(' ] - [ cnt of ')' ]
- if(ind == n){
- for(int i = 0; i < n; i++) cout<<arr[i];
- cout << endl;
- return;
- }
- if(n-ind-1 >= open+1){
- arr[ind] = '(';
- gen(ind+1, open+1);
- }
- if(open > 0){
- arr[ind] = ')';
- gen(ind+1, open-1);
- }
- }
- int main(){
- cin>>n;
- n*=2;
- arr.resize(n);
- gen(0,0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement