Skip to main content
LESSON

Sequences (2): Catalan numbers

H n = ( 2 n n ) n + 1 ( n ≥ 2 , n ∈ N + ) H_n = \frac{\binom{2n}{n}}{n+1}(n \geq 2, n \in \mathbf{N_{+}}) H n ​ = n + 1 ( n 2 n ​ ) ​ ( n ≥ 2 , n ∈ N + ​ )

The following problems belong to the Catalan sequence:

  1. Yes 2n2n Individuals line up to enter the theater. Admission is $5. Among them only nn The individual has a 5 dollar bill and another nn People only have 10 yuan bills, and there are no other bills in the theater. How many ways are there so that as long as 10 yuan people buy tickets, there will be 5 yuan bills in change at the box office?
  2. A big-city lawyer lives just north of her home nn blocks and east of nn Work in blocks. Every day she goes 2n2n blocks to work. If he never crosses (but can hit) the diagonal from home to office, how many possible paths are there?
  3. Select on circle 2n2n points, connect these points in pairs so that the obtained nn How many ways can line segments not intersect?
  4. How many ways are there to divide a convex polygon area into triangular areas when the diagonals do not intersect?
  5. The push sequence of a stack (infinity) is 1,2,3,,n1,2,3, \cdots ,n How many different pop sequences are there?
  6. nn How many different binary trees can be constructed from each node?
  7. nn a +1+1 and nn a 1-1 constitute 2n2n item a1,a2,,a2na_1,a_2, \cdots ,a_{2n}, its parts and satisfies a1+a2++ak0(k=1,2,3,,2n)a_1+a_2+ \cdots +a_k \geq 0(k=1,2,3, \cdots ,2n) Correspondence nn What is the number?

The corresponding sequence is:

H0H_0H1H_1H2H_2H3H_3H4H_4H5H_5H6H_6...
11251442132...

(Catalan sequence)

Recursive

The solution to this recurrence relation is:

Hn=(2nn)n+1(n2,nN+) H_n = \frac{\binom{2n}{n}}{n+1}(n \geq 2, n \in \mathbf{N_{+}})

Common formulas for Catalan numbers:

Hn={i=1nHi1Hnin2,nN+1n=0,1 H_n = \begin{cases} \sum_{i=1}^{n} H_{i-1} H_{n-i} & n \geq 2, n \in \mathbf{N_{+}}\\ 1 & n = 0, 1 \end{cases}

Hn=Hn1(4n2)n+1 H_n = \frac{H_{n-1} (4n-2)}{n+1}

Hn=(2nn)(2nn1) H_n = \binom{2n}{n} - \binom{2n}{n-1}

The main idea of ​​the question: The order of pushing onto the stack is $1,2,\ldots,n$, find the total number of all possible popping orders.
// C++ Version
#include <iostream>
using namespace std;
int n;
long long f[25]; int main() { f[0] = 1; cin >> n; for (int i = 1; i <= n; i++) f[i] = f[i - 1] * (4 * i - 2) / (i + 1); // Common formula 2 is used here cout << f[n] << endl; return 0;
}

path counting problem

A non-descending path is a path that can only go up or to the right.

  1. from (0,0)(0,0) Arrive (m,n)(m,n) The number of non-descending paths is equal to mm a xx and nn a yy The number of permutations, that is (n+mm)\dbinom{n + m}{m}

  2. from (0,0)(0,0) Arrive (n,n)(n,n) does not touch the straight line except for the endpoints y=xy=x The number of non-descending paths:

    Consider first y=xy=x The paths below all start from (0,0)(0, 0) set off, pass (1,0)(1, 0) and (n,n1)(n, n-1) Arrive (n,n)(n,n), can be seen as (1,0)(1,0) Arrive (n,n1)(n,n-1) no contact y=xy=x The number of non-descending paths.

    All non-descending paths have (2n2n1)\dbinom{2n-2}{n-1} article. Have any contact with any of these? y=xy=x path, you can take its last point leaving this line to (1,0)(1,0) between the parts about y=xy=x Symmetric transformation, we get from (0,1)(0,1) Arrive (n,n1)(n,n-1) a non-descending path. The reverse is also true. Thus y=xy=x The number of non-descending paths below is (2n2n1)(2n2n)\dbinom{2n-2}{n-1} - \dbinom{2n-2}{n}. According to the symmetry, the answer is 2(2n2n1)2(2n2n)2\dbinom{2n-2}{n-1} - 2\dbinom{2n-2}{n}

  3. from (0,0)(0,0) Arrive (n,n)(n,n) does not pass through a straight line except for the endpoints y=xy=x The number of non-descending paths:

    You can get it in a similar way:2n+1(2nn)\dfrac{2}{n+1}\dbinom{2n}{n}