public static List<String> generateParenthesis1(int n) {
        Set<String>[] dp = new Set[n + 1];
        Set<String> first = new HashSet<>();
        first.add("");
        dp[0] = first;
        for (int i = 1; i <= n; i++) {
            Set<String> set = new HashSet<>();
            for (String pre : dp[i - 1]) {
                set.add("(" + pre + ")");
            }
            for (int m = 1; m < i; m++) {
                for (String p1 : dp[m]) {
                    for (String p2 : dp[i - m]) {
                        set.add(p1 + p2);
                        set.add(p2 + p1);
                    }
                }
            }
            dp[i] = set;
        }
        return new ArrayList<>(dp[n]);
    }
public static List<String> generateParenthesis1(int n) {
        Set<String>[] dp = new Set[n + 1];
        Set<String> first = new HashSet<>();
        first.add("");
        dp[0] = first;
        for (int i = 1; i <= n; i++) {
            Set<String> set = new HashSet<>();
            for (String pre : dp[i - 1]) {
                set.add("(" + pre + ")");
            }
            for (int m = 1; m < i; m++) {
                for (String p1 : dp[m]) {
                    for (String p2 : dp[i - m]) {
                        set.add(p1 + p2);
                        set.add(p2 + p1);
                    }
                }
            }
            dp[i] = set;
        }
        return new ArrayList<>(dp[n]);
    }
public static list<string> generateparenthesis1(int n) { set<string>[] dp = new set[n + 1]; set<string> first = new hashset<>(); first.add(""); dp[0] = first; for (int i = 1; i <= n; i++) { set<string> set = new hashset<>(); for (string pre : dp[i - 1]) { set.add("(" + pre + ")"); } for (int m = 1; m < i; m++) { for (string p1 : dp[m]) { for (string p2 : dp[i - m]) { set.add(p1 + p2); set.add(p2 + p1); } } } dp[i] = set; } return new arraylist<>(dp[n]); }