Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int n,st[20];
- void BACK(int top,int suma,int ind)
- {
- if(top==(n+1) && suma<=n/2 && ind>=0)
- {
- for(int i=1; i<=n; i++)
- if(st[i])
- cout<<"(";
- else cout<<")";
- cout<<"\n";
- }
- else for(int i=0; i<=1 && suma<=(n/2) && ind>=0; i++)
- {
- if(!i)
- ind--;
- else ind++;
- suma+=i;
- st[top]=i;
- BACK(top+1,suma,ind);
- if(!i)
- ind++;
- else ind--;
- suma-=i;
- }
- }
- int main()
- {
- cin>>n;
- BACK(1,0,0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment