Fibonacci numbers, Cattelan numbers

1. Fibonacci sequence (rabbit sequence)

1, 1, 2, 3, 5, 8, 13, 21, ...

Recursion formula: f(1)=f(2)=1; f(n)=f(n-1)+f(n-2) (n>=3)

Quickly find f(n): matrix fast power (logn)

2. Cattelan number

1, 2, 5, 14, 42, 132, 429, 1430, 4862, ...

Recursion formula: h(0)=1, h(1)=1;  h(n)= h(0)*h(n-1)+h(1)*h(n-2) + ... + h(n-1)h(0) (n>=2)

Customs formula:h(n)=\frac{1}{n+1}\binom{n}{2n}

application:

In and out of the stack : The stack is a first-in-last-out (FILO, First In Last Out) data structure. As shown in Figure 1, 1, 2, 3, and 4 are pushed into the stack in sequence, then a possible stacking sequence is: 1In→2In→2Out→3In→4In→4Out→3Out→1Out, so the stacking sequence is 1, 3, 4,2 .

                                        

Then how many different popping sequences are there when the stacking sequence of a sufficiently large stack is 1, 2, 3, ..., n?

            We can think of it this way, assuming that k is the last number popped out of the stack. There are k-1 numbers that are pushed into the stack earlier than k and popped out of the stack earlier, and there are a total of h(k-1) schemes. There are nk numbers that are pushed into the stack later than k and popped out of the stack earlier, and there are a total of h(nk) schemes. So there are a total of h(k-1)*h(nk) schemes. Obviously, when k takes different values, the popping sequences generated are independent of each other, so the results can be accumulated. The value range of k is from 1 to n, so the result is h(n)= h(0)*h(n-1)+h(1)*h(n-2) + ... + h(n -1)h(0).

            There are many variants of the stacking and stacking problem. For example, n people get 5 yuan, n people get 10 yuan to buy items, the items are 5 yuan, and the boss has no change. Q There are several ways to line up. Students who are familiar with the stack can easily convert this problem into a stack. It is worth noting that since the queue order of everyone who takes 5 yuan is not fixed, the final answer should be *n!. The same is true for those who take 10 yuan, so *n!. So the final answer of this variant is h(n)*n!*n!.

reference:

Fibonacci sequence_IronWring_Fly's Blog-CSDN Blog

Cattelan number in detail - wookaikaiko's blog - CSDN blog

Guess you like

Origin blog.csdn.net/qq_41021141/article/details/130405864