Theory:
Make H (1) = 1, h (0) = 1, and the catalan number meets the recursive formula:
H (n) = H (0) * H (n-1) + H (1) * H (n-2) +... + H (n-1) H (0) (N> = 2)
Alternative recursion:
H (n) = (4 * N-2)/(n + 1) * H (n-1 );
The recursive relationship is resolved as follows:
H (n) = C (2n, N)/(n + 1) (n = 1, 2, 3 ,...)
The application is as follows:
1. Brackets
Matrix chain multiplication: P = A1 × a2 × A3 × ...... ×An: According to the multiplication combination law, without changing its order, we only use parentheses to represent the product of pairs. How many methods are there to enclose? (H (n)
(If you don't understand it, you can see the section "special numbers" in the ACM handout provided by Hang Dian)
2. Out-of-stack order problems
The feed sequence of a stack (infinite) is 1, 2, 3 ,..., N, how many different sequence of output stacks?
Analysis : For each number, it must be pushed to and out of the stack once. We set the status of the incoming stack to '1' and the outbound stack to '0 '. All States of N numbers correspond to a 2n binary number consisting of n 1 and N 0. The number of operations waiting for the inbound stack is arranged in the order of 1 Gb/s n. The number B of the inbound stack is greater than or equal to the value a (A ≤ B) of the outbound stack ), therefore, the total number of output sequences = the number of 2n binary numbers consisting of n 1 and N 0 from the left and right scans. The cumulative number of 1 is not less than 0.
In the 2n-bit binary number, the number of N 1 values is C (2n, n), and the remaining N values of 1 are automatically set to 0. The number of solutions that subtract the number of non-conformities (from left to right scans, and the number of accumulative counts of 0 is greater than 1) is required.
The number of non-conformities is characterized by left-to-right scans, in a certain odd digit 2 m + 1, the cumulative count of m + 1 0 and the cumulative count of M 1 will first appear, and the subsequent 2 (n-m) -1 bit has n-M 1 and n-m-1 0. If the next 2 (n-m)-1 on the 0 and 1 swap, making it n-M 0 and n-m-1 1, result 1 2n digits consisting of n + 1 0 and N-1 1 are obtained, that is, an undesired number corresponds to an arrangement consisting of n + 1 0 and N-1 1.
In turn, any 2n binary number consisting of n + 1 0 and N-1 1, because the number of 0 is two more, 2n is an even number, therefore, the cumulative count of 0 must be greater than 1 on a certain odd digit. Similarly, 0 and 1 are swapped in the following parts to form a 2n digit consisting of n 0 and N 1, that is, the 2N digits of N + 1 0 and N-1 1 must correspond to an invalid number.
Therefore, the noncompliant 2n digits correspond to n + 1 0 and N-1 1 in a one-to-one arrangement.
Obviously, the number of non-conforming solutions is C (2n, n + 1 ). The total number of output sequences = C (2n, n)-C (2n, n + 1) = 1/(n + 1) * C (2n, n) .
(The subscript of this formula starts with H (0) = 1)
Similar : There are 2n people in a row entering the theater. Admission Fee: 5 yuan. Only n people have a 5-yuan bill, N others have only 10-yuan bills, and the theater has no other money. How many ways can one buy a ticket if 10 yuan is needed, is there a change of 5 yuan worth of money at the ticket office? (The arrival of 5 yuan is regarded as 5 yuan into the stack, and the arrival of 10 yuan is regarded as a 5 yuan out of the stack) (you can find this and Beauty of Programming The question above seems the same)
3. Triangular splitting of Convex Polygon
Returns the number of methods used to divide a convex polygon area into triangle areas.
SimilarA lawyer in a big city works in N blocks north of her residence and N blocks east of her residence. Every day, she goes to work in 2n blocks. If she never cross (but can touch) the diagonal line from home to office, how many possible roads are there?
Similar: Select 2n points on the circle, and connect these points into pairs so that the resulting N line segments do not meet the number of methods? (The number of ways 2n people, seated round a table, can shake hands in N pairs, without theirArms crossing .)
4. The problem of using a given node to form a binary tree
How many different binary trees can a given n nodes constitute?
(Can constitute H (n)
Others:
Http://www.mathoe.com/dispbbs.asp? Boardid = 89 & id = 34522.
Refer:
Http://baike.baidu.com/view/2499752.htm
Http://hi.baidu.com/ask1568/blog/item/5ca3fea3b8099aa7caefd07a.html
Http://hi.baidu.com/fangqingan/blog/item/777d743508bef51b90ef39ea.html