import java.util.ArrayList;java
import java.util.List;code
import java.util.*;class
public class a_28 {import
public static void main(String args[]) {List
Scanner reader = new Scanner(System.in); System.out.println("請輸入括號對數:"); int n=reader.nextInt(); int left=n,right=n; ArrayList<String> li=new ArrayList<String>(); pattern("",left,right,li); for(String s:li) System.out.println(s);
}im
public static void pattern(String subset,int left,int right,ArrayList<String> re) {next
//成功的條件,找到了一種正確的形式 if(left==0&&right==0) { re.add(subset); } //left<right subset+")" if(left<right) { pattern(subset+")",left,right-1,re); } //當left==right>0 subset+"(" if(left>0) pattern(subset+"(",left-1,right,re);
} }static