Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package BaiToanTamHau;
- import java.util.Scanner;
- public class nghi8do {
- static int m,n, count =0;
- static int []A= new int[1000];
- static void Try(int t)
- {
- for(int i=0;i<2;i++)
- {
- A[t]=i;
- if(t == n -1)
- {
- int chan = 0,le =0;
- for(int j=0;j<n;j++)
- {
- if(A[j]== 1) chan ++;
- else le ++;
- }
- if(chan == le)
- {
- stack();
- }
- }
- else
- {
- Try(t+1);
- }
- }
- }
- static void stack()
- {
- int index =-1;
- int []B = new int [100];
- for( int i=0; i<n;i++)
- {
- if(A[i]==1 )
- {
- index++;
- B[index]= A[i];
- }
- else if(A[i]== 0 && index != -1)
- {
- if(B[index] ==1)
- {
- index --;
- }
- }
- }
- if(index == -1)
- {
- for(int i=0;i<n;i++)
- {
- if(A[i]== 1)
- {
- System.out.print('(');
- }
- else
- {
- System.out.print(')');
- }
- }
- System.out.print("\n");
- }
- }
- public static void main(String[] args)
- {
- Scanner mk = new Scanner( System.in);
- m = mk.nextInt();
- n = 2*m;
- Try(0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement