tanasaradu

Untitled

Nov 23rd, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int n,st[20];
  4. void BACK(int top,int suma,int ind)
  5. {
  6. if(top==(n+1) && suma<=n/2 && ind>=0)
  7. {
  8. for(int i=1; i<=n; i++)
  9. if(st[i])
  10. cout<<"(";
  11. else cout<<")";
  12. cout<<"\n";
  13. }
  14. else for(int i=0; i<=1 && suma<=(n/2) && ind>=0; i++)
  15. {
  16. if(!i)
  17. ind--;
  18. else ind++;
  19. suma+=i;
  20. st[top]=i;
  21. BACK(top+1,suma,ind);
  22. if(!i)
  23. ind++;
  24. else ind--;
  25. suma-=i;
  26. }
  27. }
  28. int main()
  29. {
  30. cin>>n;
  31. BACK(1,0,0);
  32. return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment