fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. char o[30];
  6. void rec(int b, int l, int p){
  7. if (l==0 && b == 0){
  8. cout << o << "\n";
  9. return;
  10. }
  11. if (b < 0)
  12. return;
  13. if (b > l)
  14. return;
  15. o[p] = '(';
  16. rec(b+1,l-1,p+1);
  17. o[p] = ')';
  18. rec(b-1,l-1,p+1);
  19. }
  20.  
  21. int main()
  22. {
  23. int n;
  24. cin >> n;
  25. rec(0,2*n,0);
  26. }
Success #stdin #stdout 0s 4308KB
stdin
4
stdout
(((())))
((()()))
((())())
((()))()
(()(()))
(()()())
(()())()
(())(())
(())()()
()((()))
()(()())
()(())()
()()(())
()()()()