Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int x[101], n;
- void tipar()
- {
- for(int i=1; i<=n; i++)
- {
- if(x[i]==0)
- cout<<'('<<' ';
- else
- cout<<')'<<' ';
- }
- cout<<'\n';
- }
- bool e_bun(int k)
- {
- int cated=0, catei=0;
- for(int i=1; i<=k; i++)
- if(x[i]==0)
- cated++;
- else
- catei++;
- if(cated>n/2)
- return 0;
- if(cated<catei)
- return 0;
- return 1;
- }
- void back()
- {
- int k=1;
- x[k]=-1;
- while(k>0)
- {
- if(x[k]<1)
- {
- x[k]++;
- if(e_bun(k))
- if(k==n)
- tipar();
- else
- {
- k++;
- x[k]=-1;
- }
- }
- else
- k--;
- }
- }
- int main()
- {
- cin>>n;
- back();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment