Advertisement
Guest User

Dayngoac4/7/2020

a guest
Apr 6th, 2020
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.05 KB | None | 0 0
  1. package BaiToanTamHau;
  2. import java.util.Scanner;
  3. public class nghi8do {
  4.     static int m,n, count =0;
  5.     static int []A= new int[1000];
  6.     static void Try(int t)
  7.     {
  8.         for(int i=0;i<2;i++)
  9.         {
  10.             A[t]=i;
  11.             if(t == n -1)
  12.             {
  13.                 int chan = 0,le =0;
  14.                 for(int j=0;j<n;j++)
  15.                 {
  16.                     if(A[j]== 1) chan ++;
  17.                     else le ++;
  18.                 }
  19.                 if(chan == le)
  20.                 {
  21.                     stack();
  22.                 }
  23.             }
  24.             else
  25.             {
  26.                 Try(t+1);
  27.             }
  28.         }
  29.        
  30.     }
  31.     static void stack()
  32.     {
  33.         int index =-1;
  34.         int []B = new int [100];
  35.         for( int i=0; i<n;i++)
  36.         {
  37.             if(A[i]==1 )
  38.             {
  39.                 index++;
  40.                 B[index]= A[i];
  41.             }
  42.             else if(A[i]== 0 && index != -1)
  43.             {
  44.                 if(B[index] ==1)
  45.                 {
  46.                     index --;
  47.                 }
  48.             }
  49.         }
  50.         if(index == -1)
  51.         {
  52.             for(int i=0;i<n;i++)
  53.             {
  54.                 if(A[i]== 1)
  55.                 {
  56.                     System.out.print('(');
  57.                 }
  58.                 else
  59.                 {
  60.                     System.out.print(')');
  61.                 }
  62.             }
  63.             System.out.print("\n");
  64.         }
  65.     }
  66.     public static void main(String[] args)
  67.     {
  68.         Scanner mk = new Scanner( System.in);
  69.         m = mk.nextInt();
  70.         n = 2*m;
  71.         Try(0);
  72.        
  73.     }
  74.  
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement