# [BZOJ4001] [TJOI2015] 概率论 [期望计数] [卡特兰数&打表 / 生成函数&广义二项式定理]

[ L i n k \frak{Link} ]

C 0 = 1 , C 1 = 1 , C 2 = 2 , C 3 = 5 , C 4 = 14 , C 5 = 42 C_0=1,C_1=1,C_2=2,C_3=5,C_4=14,C_5=42

p = n p=n 即可。然后按照 2 n 2^n 进制（不是 2 进制！）来分离各位。

String 公式可以快速求阶乘。

//打表。
//nSch[i][j] 表示 i 个点 j 个叶子的二叉树的数量
//不能太急，如果上来直接就打叶子总数，会很麻烦。
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
const int MAXN = 1e4;
int nMax;
unsigned long long nTemp, nSch[MAXN][MAXN];
int main()
{
cin >> nMax;
nSch[0][0] = nSch[1][1] = 1;
for (int nNodeSum = 2; nNodeSum <= nMax; ++nNodeSum)
{
for (int nLeaFSum = 1; nLeaFSum <= ((nNodeSum + 1) >> 1); ++nLeaFSum)
{
for (int nLeftNode = 0; nLeftNode < nNodeSum; ++nLeftNode)
{
for (int nLeftLeaF = 0; nLeftLeaF <= nLeaFSum; ++nLeftLeaF)
{
nSch[nNodeSum][nLeaFSum] += nSch[nLeftNode][nLeftLeaF] * nSch[nNodeSum - nLeftNode - 1][nLeaFSum - nLeftLeaF];
}
}
}
}
for (int nLim, i = 1; i <= nMax; ++i)
{
nTemp = 0, nLim = (i + 1) >> 1;
for (int j = 1; j <= nLim; ++j) nTemp += nSch[i][j] * j;
printf("%d %lld\n", i, nTemp);
}
return 0;
}

20

1  1
2  2
3  6
4  20
5  70
6  252
7  924
8  3432
9  12870

--------------------------------
Process exited with return value 0
Press any key to continue . . .


∵ A n s n = n C n − 1 C n \because Ans_n = \frac{nC_{n-1}}{C_{n}}
∵ C n = 4 n − 2 n + 1 C n − 1 \because C_{n}=\frac{4n-2}{n+1}C_{n-1}
∴ A n s n = n ( n + 1 ) 4 n − 2 \therefore Ans_n = \frac{n(n+1)}{4n-2}

#include<cstdio>
double n;
int main()
{
scanf("%lf", &n);
printf("%.9f", n * (n + 1.0) / (n * 4.0 - 2.0));
return 0;
}


( a + b ) n = ∑ i = 0 n ( n i ) a i b n − i (a+b)^n=\sum\limits_{i=0}^n{n\choose i}a^ib^{n-i}

A n = { 0 n = 0 1 n = 1 2 ∑ i = 0 n − 1 A i C n − i − 1 n ≥ 2 A_n=\begin{cases} 0 &amp; n=0 \\ 1 &amp; n=1 \\ 2\sum\limits_{i=0}^{n-1}A_iC_{n-i-1} &amp; n\ge2 \end{cases}
C n = { 1 n = 0 ∑ i = 0 n − 1 C i C n − i − 1 n ≥ 1 C_n=\begin{cases} 1&amp;n=0 \\ \sum\limits_{i=0}^{n-1}C_iC_{n-i-1} &amp; n\ge1 \end{cases}

α ( x ) = x + ∑ n = 0 ∞ 2 x n ∑ i = 0 n − 1 A i C n − i − 1 = x + 2 x ⋅ α ( x ) β ( x ) = x + 2 x ⋅ α ( x ) ⋅ 1 − 1 − 4 x 2 x = x + α ( x ) − α ( x ) ⋅ 1 − 4 x \begin{array}{lll} \alpha(x) &amp; = &amp; x+\sum\limits_{n=0}^\infty2x^n\sum\limits_{i=0}^{n\bm-1}A_iC_{n\bm-i\bm-1} \\ &amp; = &amp; x+2x\cdot\alpha(x)\beta(x) \\ &amp; = &amp; x+2x\cdot\alpha(x)\cdot\frac{1\bm-\sqrt{1\bm-4x}}{2x} \\ &amp; = &amp; x+\alpha(x)\bm-\alpha(x)\cdot\sqrt{1\bm-4x} \end{array}

α ( x ) = x 1 − 4 x = x ( 1 − 4 x ) − 0.5 \begin{array}{lll} \alpha(x)&amp;=&amp;\frac{x}{\sqrt{1\bm-4x}}\\ &amp;=&amp;x(1\bm-4x)^{\bm -0.5} \end{array}

( 1 − 4 x ) − 0.5 (1\bm-4x)^{\bm -0.5} 展开后第 n − 1 n-1 项为
− 0.5 ( − 0.5 − 1 ) ⋯ [ − 0.5 − ( n − 1 ) + 1 ] ( n − 1 ) ! ⋅ ( − 4 x ) n − 1 = ( − 1 ) n − 1 ⋅ ∏ i = 1 n − 1 ( 2 i − 1 ) ( n − 1 ) ! 2 n − 1 ⋅ ( − 1 ) n − 1 ⋅ 4 n − 1 ⋅ x n − 1 \begin{array}{ll} &amp;\displaystyle{\frac{-0.5(-0.5-1)\cdots[-0.5-(n-1)+1]}{(n-1)!}}\cdot(-4x)^{n-1}\\ \displaystyle=&amp;\displaystyle\frac{(-1)^{n-1}\cdot\prod\limits_{i=1}^{n-1}(2i-1)}{(n-1)!2^{n-1}}\cdot(-1)^{n-1}\cdot4^{n-1}\cdot x^{n-1}\\ \end{array}

( − 1 ) n − 1 ⋅ ∏ i = 1 n − 1 ( 2 i − 1 ) ( n − 1 ) ! 2 n − 1 ⋅ ( − 1 ) n − 1 ⋅ 4 n − 1 = ( 2 n − 3 ) ! ( n − 1 ) ! 2 n − 1 ∏ i = 1 n − 2 2 i ⋅ 4 n − 1 = ( 2 n − 3 ) ! ( n − 1 ) ! 2 n − 2 ( n − 2 ) ! ⋅ 2 n − 1 = 2 ( 2 n − 3 ) ! ( n − 1 ) ! ( n − 2 ) ! \begin{array}{ll} &amp;\displaystyle\frac{(-1)^{n-1}\cdot\prod\limits_{i=1}^{n-1}(2i-1)}{(n-1)!2^{n-1}}\cdot(-1)^{n-1}\cdot4^{n-1}\\ =&amp;\displaystyle\frac{(2n-3)!}{(n-1)!2^{n-1}\prod\limits_{i=1}^{n-2}2i}\cdot4^{n-1}\\ \displaystyle=&amp;\displaystyle\frac{(2n-3)!}{(n-1)!2^{n-2}(n-2)!}\cdot2^{n-1}\\ \displaystyle=&amp;\displaystyle\frac{2(2n-3)!}{(n-1)!(n-2)!} \end{array}

2 ( 2 n − 3 ) ! ( n − 1 ) ! ( n − 2 ) ! \frac{2(2n-3)!}{(n-1)!(n-2)!}

2 ⋅ ( 2 n − 3 ) ! ( n − 1 ) ! ⋅ ( n − 2 ) ! ⋅ C n = 2 ⋅ ( 2 n − 3 ) ! ⋅ n ! ⋅ ( n + 1 ) ! ( n − 1 ) ! ⋅ ( n − 2 ) ! ⋅ ( 2 n ) ! = 2 ⋅ n ⋅ ( n − 1 ) ⋅ n ⋅ ( n + 1 ) ( 2 n − 2 ) ⋅ ( 2 n − 1 ) ⋅ ( 2 n ) = n ⋅ ( n + 1 ) 2 ⋅ ( 2 n − 1 ) = n ( n + 1 ) 4 n − 2 \begin{array}{lll} \displaystyle\frac{2\cdot(2n-3)!}{(n-1)!\cdot(n-2)!\cdot C_n}&amp;\displaystyle=&amp;\displaystyle\frac{2\cdot(2n-3)!\cdot n!\cdot(n+1)!}{(n-1)!\cdot(n-2)!\cdot(2n)!} \\ &amp;\displaystyle=&amp;\displaystyle\frac{2\cdot n\cdot (n-1)\cdot n\cdot (n+1)}{(2n-2)\cdot(2n-1)\cdot(2n)}\\ &amp;\displaystyle=&amp;\displaystyle\frac{n\cdot(n+1)}{2\cdot(2n-1)}\\ &amp;\displaystyle=&amp;\displaystyle\frac{n(n+1)}{4n-2} \end{array}

• 0
点赞
• 0
评论
• 0
收藏
• 一键三连
• 扫一扫，分享海报

04-23 59
10-20 39

05-14 763
12-31 254
12-27 293
05-19 46
10-18 40
08-18 1913
04-02 266
06-18 123
10-14 108
08-31 343
09-28 606
01-03 116