Algorithm Exercises: Cattleya Numbers

Cattleya number

Catalan number, also known as Catalan number, is a sequence in combinatorial mathematics that often appears in various counting problems. The first few are:
1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 58786, 208012, 742900, 2674440, 9694845, 35357670, 129644790, 4776 38700, 1767263190, 6564120420, 24466267020, 91482563640, 343059613650, 1289904147324, 4861946401452, …

When k(0) = 1, k(1) = 1, if the next term satisfies:
k(n) = k(0) * k(n - 1) + k(1) * k(n - 2) + … + k(n - 2) * k(1) + k(n - 1) * k(0)
or
k(n) = c(2n, n) - c(2n, n-1)
or
k( n) = c(2n, n) / (n + 1)
This expression satisfies the Catalan number. Paradigms 1 and 2 are commonly used, and paradigm 3 is rarely used.

Exercise 1 Suppose you are given N 0s and N 1s. You must use all the numbers to spell the sequence and return how many sequences satisfy: for any prefix string, the number of 1s is not less than the number of 0s.

Exercise 2 There are N binary tree nodes, and each node has no difference between each other. How many different structures are returned composed of N binary tree nodes?

How to discover the algorithm prototype of Cattleya number when solving problems?

1) If it is like question 1, this is too obvious, you will definitely find it.
2) See if the question is similar to question 2, such as:
personnel lining up problem,
pop-in stack problem

Guess you like

Origin blog.csdn.net/sam475259540/article/details/131489655