Combinatorial mathematics - number Cattleya

We have a question as an example to introduce Cartland number:

  Topic links: meet the 01 series of conditions

Given n number 0 and n- 1, they are arranged in a certain order of length sequence of 2n, they can find all of the sequences are arranged, it is possible to meet any prefix sequence number 0 are less than 1 sequence number of how many.

The answer to the output 10 . 9 + 7 mod.

  In order to facilitate the solution, we can put this problem into:

Given an n * n matrix, each step can only go right or go up, go seek the apex of all programs in the upper right corner from the lower left corner vertex, the number of steps walked a few steps to the right of not less than going up the number of programs, and in 10 . 9 +7 modulo.

  We then target step conversion:

Path = total number of legitimate path - Illegal number of paths

  Wherein the total number of paths is the number of combinations is clearly C 12 is . 6 , so that the next number of paths to only illegal demand.

  N = 6 we give examples of view:

  As shown below:

  

  Went to (6,6) from (0,0) path is the path of all the total path.

  Obviously, all the paths are lawful black line path , the path as shown in FIG green line is a legitimate path.

  And any one path through the illegal path must be red , blue line path shown in FIG.

  We then the illegal path portion after the first pass through the red symmetrically on red, yellow line shown in FIG.

  Difficult to find any illegal path as a symmetry operation after the end point must be (5,7).

  进而又可以发现,从(0,0)到(5,7)的任何一条路径进行如上对称操作后一定是一条非法路径。

  故从(0,0)到(5,7)的路径与非法路径构成双射。

  那么显然,非法路径数即是组合数C125

  所以合法路径数就是C126 - C125。

  而我们又可以发现,C2nn - C2nn-1 = C2nn/(n+1)。

  这就是卡特兰数

  而上述该题正是卡特兰数的一个应用。


 卡特兰数:

  以下内容参考百度百科:卡特兰数

卡特兰数又称卡塔兰数,卡特兰数是组合数学中一个常出现在各种计数问题中的数列。以比利时的数学家欧仁·查理·卡塔兰 (1814–1894)的名字来命名。

原理:

设h(n)为catalan数的第n项,令h(0)=1,h(1)=1,catalan数满足递推式

h(n)= h(0)*h(n-1)+h(1)*h(n-2) + ... + h(n-1)*h(0) (n>=2)

例如:h(2)=h(0)*h(1)+h(1)*h(0)=1*1+1*1=2

h(3)=h(0)*h(2)+h(1)*h(1)+h(2)*h(0)=1*2+1*1+2*1=5

另类递推式:

h(n)=h(n-1)*(4*n-2)/(n+1);

递推关系的解为:

h(n)=C(2n,n)/(n+1) (n=0,1,2,...)

递推关系的另类解为:

h(n)=c(2n,n)-c(2n,n-1)(n=0,1,2,...)

 


 卡特兰数的常见应用:

一、出栈次序

一个栈(无穷大)的进栈序列为1,2,3,…,n,有多少个不同的出栈序列?

二、括号化

矩阵连乘: P=a1×a2×a3×……×an,依据乘法结合律,不改变其顺序,只用括号表示成对的乘积,试问有几种括号化的方案?(h(n)种)

三、凸多边形三角划分

在一个凸多边形中,通过若干条互不相交的对角线,把这个多边形划分成了若干个三角形。任务是键盘上输入凸多边形的边数n,求不同划分的方案数f(n)。比如当n=6时,f(6)=14。

四、给定节点组成二叉搜索树

给定N个节点,能构成多少种不同的二叉搜索树(能构成h(n)个)

五、n对括号正确匹配数目

给定n对括号,求括号正确配对的字符串数。

Guess you like

Origin www.cnblogs.com/ninedream/p/11223009.html