组合数
( n m ) \dbinom{n}{m} (mn):从 n n n 个物品中选出 m m m 个的方案数。
-
( n m ) = n ! m ! ( n − m ) ! = n m ‾ m ! \dbinom{n}{m}=\dfrac{n!}{m!(n-m)!}=\dfrac{n^{\underline{m}}}{m!} (mn)=m!(n−m)!n!=m!nm
(这个式子只依靠经典的组合意义,所以只在 0 ≤ m ≤ n 0\leq m\leq n 0≤m≤n 时确保成立。)
推论:
对称性: ( n m ) = ( n n − m ) \dbinom{n}{m}=\dbinom{n}{n-m} (mn)=(n−mn)
吸收/释放: ( n m ) = n m ( n − 1 m − 1 ) \dbinom{n}{m}=\dfrac{n}{m}\dbinom{n-1}{m-1} (mn)=mn(m−1n−1) -
递推公式: ( n m ) = ( n − 1 m ) + ( n − 1 m − 1 ) \dbinom{n}{m}=\dbinom{n-1}{m}+\dbinom{n-1}{m-1} (mn)=(mn−1)+(m−1n−1)
推论:
平行求和: ∑ i = 0 n ( r + i i ) = ( r + n + 1 n ) \sum\limits_{i=0}^{n}\dbinom{r+i}{i}=\dbinom{r+n+1}{n} i=0∑n(ir+i)=(nr+n+1)
证明: ∑ i = 0 n ( r + i i ) = ( r 0 ) + ( r + 1 1 ) + ( r + 2 2 ) + . . . + ( r + n n ) = ( r + 1 0 ) + ( r + 1 1 ) + ( r + 2 2 ) + . . . + ( r + n n ) = ( r + 2 1 ) + ( r + 2 2 ) + . . . + ( r + n n ) = ( r + 3 2 ) + . . . + ( r + n n ) = ( r + n + 1 n ) \sum\limits_{i=0}^{n}\binom{r+i}{i}\\=\binom{r}{0}+\binom{r+1}{1}+\binom{r+2}{2}+...+\binom{r+n}{n}\\=\binom{r+1}{0}+\binom{r+1}{1}+\binom{r+2}{2}+...+\binom{r+n}{n}\\=\binom{r+2}{1}+\binom{r+2}{2}+...+\binom{r+n}{n}\\=\binom{r+3}{2}+...+\binom{r+n}{n}\\=\binom{r+n+1}{n} i=0∑n(ir+i)=(0r)+(1r+1)+(2r+2)+...+(nr+n)=(0r+1)+(1r+1)+(2r+2)+...+(nr+n)=(1r+2)+(2r+2)+...+(nr+n)=(2r+3)+...+(nr+n)=(nr+n+1)
上指标求和: ∑ i = 0 n ( i m ) = ( n + 1 m + 1 ) \sum\limits_{i=0}^{n}\dbinom{i}{m}=\dbinom{n+1}{m+1} i=0∑n(mi)=(m+1n+1)
证明: ∑ i = 0 n ( i m ) = ( m m ) + ( m + 1 m ) + ( m + 2 m ) + . . . + ( n m ) = ( m + 1 m + 1 ) + ( m + 1 m ) + ( m + 2 m ) + . . . + ( n m ) = ( m + 2 m + 1 ) + ( m + 2 m ) + . . . + ( n m ) = ( m + 3 m + 1 ) + . . . + ( n m ) = ( n + 1 m + 1 ) \sum\limits_{i=0}^{n}\binom{i}{m}\\=\binom{m}{m}+\binom{m+1}{m}+\binom{m+2}{m}+...+\binom{n}{m}\\=\binom{m+1}{m+1}+\binom{m+1}{m}+\binom{m+2}{m}+...+\binom{n}{m}\\=\binom{m+2}{m+1}+\binom{m+2}{m}+...+\binom{n}{m}\\=\binom{m+3}{m+1}+...+\binom{n}{m}\\=\binom{n+1}{m+1} i=0∑n(mi)=(mm)+(mm+1)+(mm+2)+...+(mn)=(m+1m+1)+(mm+1)+(mm+2)+...+(mn)=(m+1m+2)+(mm+2)+...+(mn)=(m+1m+3)+...+(mn)=(m+1n+1) -
经典二项式定理: ( x + y ) k = ∑ i = 0 k ( k i ) x i y k − i (x+y)^k=\sum\limits_{i=0}^{k}\dbinom{k}{i}x^iy^{k-i} (x+y)k=i=0∑k(ik)xiyk−i
-
范德蒙德卷积:
结论: ( n + m k ) = ∑ i = 0 k ( n i ) ( m k − i ) \dbinom{n+m}{k}=\sum\limits_{i=0}^{k}\dbinom{n}{i}\dbinom{m}{k-i} (kn+m)=i=0∑k(in)(k−im)
证明:首先显然有 ( 1 + x ) n + m = ( 1 + x ) n ( 1 + x ) m (1+x)^{n+m}=(1+x)^n(1+x)^m (1+x)n+m=(1+x)n(1+x)m
那么 ∑ k = 0 n + m ( n + m k ) x k = ∑ i = 0 n ( n i ) x i ∑ j = 0 m ( m j ) x j \sum\limits_{k=0}^{n+m}\binom{n+m}{k}x^k=\sum\limits_{i=0}^{n}\binom{n}{i}x^i\sum\limits_{j=0}^{m}\binom{m}{j}x^j k=0∑n+m(kn+m)xk=i=0∑n(in)xij=0∑m(jm)xj
∑ k = 0 n + m ( n + m k ) x k = ∑ i = 0 n ∑ j = 0 m ( n i ) ( m j ) x i + j \sum\limits_{k=0}^{n+m}\binom{n+m}{k}x^k=\sum\limits_{i=0}^{n}\sum\limits_{j=0}^{m}\binom{n}{i}\binom{m}{j}x^{i+j} k=0∑n+m(kn+m)xk=i=0∑nj=0∑m(in)(jm)xi+j
∑ k = 0 n + m ( n + m k ) x k = ∑ k = 0 n + m ∑ i = 0 k ( n i ) ( m k − i ) x k \sum\limits_{k=0}^{n+m}\binom{n+m}{k}x^k=\sum\limits_{k=0}^{n+m}\sum\limits_{i=0}^{k}\binom{n}{i}\binom{m}{k-i}x^{k} k=0∑n+m(kn+m)xk=k=0∑n+mi=0∑k(in)(k−im)xk
[ x k ] ∑ k = 0 n + m ( n + m k ) x k = [ x k ] ∑ k = 0 n + m ∑ i = 0 k ( n i ) ( m k − i ) x k [x^k]\sum\limits_{k=0}^{n+m}\binom{n+m}{k}x^k=[x^k]\sum\limits_{k=0}^{n+m}\sum\limits_{i=0}^{k}\binom{n}{i}\binom{m}{k-i}x^{k} [xk]k=0∑n+m(kn+m)xk=[xk]k=0∑n+mi=0∑k(in)(k−im)xk
( n + m k ) = ∑ i = 0 k ( n i ) ( m k − i ) \binom{n+m}{k}=\sum\limits_{i=0}^{k}\binom{n}{i}\binom{m}{k-i} (kn+m)=i=0∑k(in)(k−im)
推论:
∑ i = 1 n ( n i ) ( n i − 1 ) = ( 2 n n − 1 ) \sum\limits_{i=1}^n\dbinom ni\dbinom {n}{i-1}=\dbinom {2n}{n-1} i=1∑n(in)(i−1n)=(n−12n)
证明: ( 2 n n − 1 ) = ∑ i = 0 n − 1 ( n i ) ( n n − 1 − i ) = ∑ i = 0 n − 1 ( n i ) ( n i + 1 ) = ∑ i = 1 n ( n i ) ( n i − 1 ) \binom {2n}{n-1}= \sum\limits_{i=0}^{n-1}\binom ni\binom n{n-1-i}=\sum\limits_{i=0}^{n-1}\binom ni\binom n{i+1}=\sum\limits_{i=1}^{n}\binom ni\binom n{i-1} (n−12n)=i=0∑n−1(in)(n−1−in)=i=0∑n−1(in)(i+1n)=i=1∑n(in)(i−1n)
∑ i = 0 m ( n i ) ( m i ) = ( n + m m ) \sum\limits_{i=0}^m\dbinom ni\dbinom mi=\dbinom {n+m}m i=0∑m(in)(im)=(mn+m)
证明: ∑ i = 0 m ( n i ) ( m i ) = ∑ i = 0 m ( n i ) ( m m − i ) = ( n + m m ) \sum\limits_{i=0}^m\binom ni\binom mi=\sum\limits_{i=0}^m\binom ni\binom m{m-i}=\binom {n+m}m i=0∑m(in)(im)=i=0∑m(in)(m−im)=(mn+m)
广义二项式系数
广义二项式系数 :
(
α
i
)
=
α
i
‾
i
!
\dbinom{\alpha}{i}=\dfrac{\alpha^{\underline {i}}}{i!}
(iα)=i!αi
(
α
\alpha
α可以是实数(或者更多?))
- 广义二项式定理:
(
x
+
y
)
α
=
∑
i
=
0
∞
(
α
i
)
x
i
y
k
−
i
(x+y)^{\alpha}=\sum\limits_{i=0}^{\infty}\dbinom{\alpha}{i}x^iy^{k-i}
(x+y)α=i=0∑∞(iα)xiyk−i
(普通二项式定理求和到 α \alpha α就停下,是因为之后的组合数都是 0 0 0,可弃掉) - 上指标反转 :认识和处理上指标为负(整)数的组合数。
( r k ) = ( − 1 ) k ( k − r − 1 k ) \dbinom{r}{k}=(-1)^k\dbinom{k-r-1}{k} (kr)=(−1)k(kk−r−1)
证明: r k ‾ k ! = ( − 1 ) k ( − r ) k ‾ k ! = ( − 1 ) k ( − r ) ( − r + 1 ) . . . ( − r + k − 1 ) k ! = ( − 1 ) k ( k − r − 1 ) k ‾ k ! \frac{r^{\underline{k}}}{k!}=\frac{(-1)^k(-r)^{\overline{k}}}{k!}=\frac{(-1)^k(-r)(-r+1)...(-r+k-1)}{k!}=\frac{(-1)^k(k-r-1)^{\underline{k}}}{k!} k!rk=k!(−1)k(−r)k=k!(−1)k(−r)(−r+1)...(−r+k−1)=k!(−1)k(k−r−1)k - 取一半:处理
(
2
n
n
)
\dbinom{2n}{n}
(n2n) 形组合数。
由 x k ‾ ( x − 1 2 ) k ‾ = ( 2 x ) 2 k ‾ 2 2 k x^{\underline{k}}(x-\frac{1}{2})^{\underline{k}}=\frac{(2x)^{\underline{2k}}}{2^{2k}} xk(x−21)k=22k(2x)2k 知,
n n ‾ ( n − 1 2 ) n ‾ = ( 2 n ) 2 n ‾ 2 2 n n^{\underline{n}}(n-\frac{1}{2})^{\underline{n}}=\frac{(2n)^{\underline{2n}}}{2^{2n}} nn(n−21)n=22n(2n)2n
n n ‾ ( n − 1 2 ) n ‾ = ( 2 n ) n ‾ n n ‾ 2 2 n n^{\underline{n}}(n-\frac{1}{2})^{\underline{n}}=\frac{(2n)^{\underline{n}}n^{\underline{n}}}{2^{2n}} nn(n−21)n=22n(2n)nnn
等式两边同时除以 ( n ! ) 2 (n!)^2 (n!)2,得到
( n n ) ( n − 1 2 n ) = 1 2 2 n ( 2 n n ) ( n n ) \binom{n}{n}\binom{n-\frac{1}{2}}{n}=\frac{1}{2^{2n}}\binom{2n}{n}\binom{n}{n} (nn)(nn−21)=22n1(n2n)(nn)
( n − 1 2 n ) = 1 4 n ( 2 n n ) \binom{n-\frac{1}{2}}{n}=\frac{1}{4^n}\binom{2n}{n} (nn−21)=4n1(n2n)
反转上指标:
( − 1 ) n ( 1 2 − 1 n ) = 1 4 n ( 2 n n ) (-1)^n\binom{\frac{1}{2}-1}{n}=\frac{1}{4^n}\binom{2n}{n} (−1)n(n21−1)=4n1(n2n)
( 2 n n ) = ( − 4 ) n ( − 1 2 n ) {\color{Goldenrod}\dbinom{2n}{n}=(-4)^n\dbinom{-\frac{1}{2}}{n} } (n2n)=(−4)n(n−21)
∑ i = 0 ∞ ( 2 i i ) x i = ∑ i = 0 ∞ ( − 1 2 i ) ( − 4 x ) i × 1 ( − 1 2 − i ) = ( 1 − 4 x ) − 1 2 {\color{Goldenrod}\sum\limits_{i=0}^{\infty}\dbinom{2i}{i}x^i=\sum\limits_{i=0}^{\infty}\dbinom{-\frac{1}{2}}{i}(-4x)^i\times 1^{(-\frac{1}{2}-i)}=(1-4x)^{-\frac{1}{2}}} i=0∑∞(i2i)xi=i=0∑∞(i−21)(−4x)i×1(−21−i)=(1−4x)−21 - 阶乘幂的二项式定理:
当 n n n 是自然数时,有
( x + y ) n ‾ = ∑ i = 0 n ( n i ) x i ‾ y n − i ‾ (x+y)^{\underline{n}}=\sum\limits_{i=0}^n\dbinom{n}{i}x^{\underline i}y^{\underline{n-i}} (x+y)n=i=0∑n(in)xiyn−i
( x + y ) n ‾ = ∑ i = 0 n ( n i ) x i ‾ y n − i ‾ (x+y)^{\overline{n}}=\sum\limits_{i=0}^n\dbinom{n}{i}x^{\overline i}y^{\overline{n-i}} (x+y)n=i=0∑n(in)xiyn−i
二项式反演
差分与前缀和
n
n
n 阶差分是 :
Δ
n
f
(
x
)
=
∑
i
=
0
n
(
n
i
)
(
−
1
)
n
−
i
f
(
x
+
i
)
\Delta^{n} f(x)=\sum\limits_{i=0}^n\dbinom{n}{i}(-1)^{n-i}f(x+i)
Δnf(x)=i=0∑n(in)(−1)n−if(x+i)
n
n
n 阶前缀和是 :
Σ
n
f
(
x
)
=
∑
i
=
0
(
n
+
i
−
1
i
)
f
(
x
−
i
)
\Sigma^{n} f(x)=\sum\limits_{i=0}\dbinom{n+i-1}{i}f(x-i)
Σnf(x)=i=0∑(in+i−1)f(x−i)(注意,没有指明上界)
牛顿级数
若 R i ( x ) R_i(x) Ri(x) 是关于 x x x 的 i i i 次多项式,我们总能在系数合适的时候用 ∑ i = 0 m c i R i ( x ) \sum\limits_{i=0}^mc_iR_i(x) i=0∑mciRi(x) 来描述任意多项式。
现在,我们令 R i ( x ) = ( x i ) = x i ‾ i ! R_i(x)=\dbinom{x}{i}=\dfrac{x^{\underline i}}{i!} Ri(x)=(ix)=i!xi,这是符合要求的。
我们就能得到牛顿级数: F ( x ) = ∑ i = 0 m F [ i ] ( x i ) F(x)=\sum\limits_{i=0}^mF[i]\dbinom{x}{i} F(x)=i=0∑mF[i](ix)
根据递推公式,能得到结论: Δ x ( x k ) = ( x k − 1 ) \Delta_x\dbinom{x}{k}=\dbinom{x}{k-1} Δx(kx)=(k−1x)
所以 Δ n F ( x ) = ∑ i = n m F [ i ] ( x i − n ) {\color{GoldenRod}\Delta^nF(x)=\sum\limits_{i=n}^mF[i]\dbinom{x}{i-n}} ΔnF(x)=i=n∑mF[i](i−nx)
对
F
(
x
)
=
∑
i
=
0
(
x
i
)
F
[
i
]
F(x)=\sum\limits_{i=0}\dbinom{x}{i}F[i]
F(x)=i=0∑(ix)F[i] 使用二项式反演可得:
F
[
x
]
=
∑
i
=
0
(
x
i
)
(
−
1
)
m
−
i
F
(
i
)
{\color{GoldenRod}F[x]=\sum\limits_{i=0}\dbinom{x}{i}(-1)^{m-i}F(i)}
F[x]=i=0∑(ix)(−1)m−iF(i)
二项式反演是可以
N
T
T
NTT
NTT卷积加速的,所以我们能在
O
(
n
log
n
)
O(n\log n)
O(nlogn) 内做到 :
0
⋯
m
点
值
⟺
牛
顿
级
数
0\cdots m点值\Longleftrightarrow牛顿级数
0⋯m点值⟺牛顿级数 。
生成函数与杨辉三角
-
将杨辉三角(可以看作二维数组)写成二元生成函数的形式 :
数组)写成二元生成函数的形式 :
G [ n , m ] = ( n m ) G ( x , y ) = ∑ i = 0 ∑ j = 0 ( i j ) x i y j = ∑ i = 0 x i ( y + 1 ) i = 1 1 − x − x y \begin{aligned} G[n,m]&=\dbinom{n}{m}\\ G(x,y)&=\sum\limits_{i=0}\sum\limits_{j=0}\dbinom{i}{j}x^iy^j\\ &=\sum\limits_{i=0}x^i(y+1)^i\\ &=\dfrac{1}{1-x-xy} \end{aligned} G[n,m]G(x,y)=(mn)=i=0∑j=0∑(ji)xiyj=i=0∑xi(y+1)i=1−x−xy1
这个简洁的封闭形式将整个杨辉三角蕴含其中。 -
如果将 y y y 替换为关于 x x x 的式子,或将 x x x 替换为关于 y y y 的式子,从二元变成一元, x a y b x^ay^b xayb 的系数会根据某些条件合并。
例如,
令 y = x k y=x^k y=xk,则 [ x n ] G ( x , x k ) = [ x n ] ∑ i = 0 ∑ j = 0 ( i j ) x i x j k = ∑ i + j × k = n ( i j ) [x^n]G(x,x^k)=[x^n]\sum\limits_{i=0}\sum\limits_{j=0}\dbinom{i}{j}x^ix^{jk}=\sum\limits_{i+j\times k=n}\dbinom{i}{j} [xn]G(x,xk)=[xn]i=0∑j=0∑(ji)xixjk=i+j×k=n∑(ji)
令 x = y k x=y^k x=yk,则 [ x n ] G ( y k , y ) = [ x n ] ∑ i = 0 ∑ j = 0 ( i j ) x i k x j = ∑ i × k + j = n ( i j ) [x^n]G(y^k,y)=[x^n]\sum\limits_{i=0}\sum\limits_{j=0}\dbinom{i}{j}x^{ik}x^j=\sum\limits_{i\times k+j=n}\dbinom{i}{j} [xn]G(yk,y)=[xn]i=0∑j=0∑(ji)xikxj=i×k+j=n∑(ji)
这是杨辉三角上某个奇怪方向的求和。同时,考察封闭形式即可得到系数。
更多的求和 :
-
∑ i = 0 m ( m i ) \sum\limits_{i=0}^m\dbinom{m}{i} i=0∑m(im)
即为 ∑ i + j × 0 = m ( i j ) \sum\limits_{i+j\times 0=m}\dbinom{i}{j} i+j×0=m∑(ji),所以令 y = x 0 y=x^0 y=x0 得到 G ( x , 1 ) = 1 1 − 2 x G(x,1)=\dfrac{1}{1-2x} G(x,1)=1−2x1。提取系数得 ∑ i = 0 m ( m i ) = [ x m ] 1 1 − 2 x = 2 m \sum\limits_{i=0}^m\dbinom{m}{i}=[x^m]\dfrac{1}{1-2x}=2^m i=0∑m(im)=[xm]1−2x1=2m -
∑ i = 0 m ( i + m 2 i ) \sum\limits_{i=0}^m\dbinom{i+m}{2i} i=0∑m(2ii+m)
注意到 i + m − ( 2 i ) / 2 = m i + m − ( 2 i ) / 2 = m i+m-(2i)/2=mi+m−(2i)/2=m i+m−(2i)/2=mi+m−(2i)/2=m ,故上式即为 ∑ i − j / 2 = m ( i j ) \sum\limits_{i-j/2=m}\dbinom{i}{j} i−j/2=m∑(ji) 。令 y = x − 1 / 2 y=x^{-1/2} y=x−1/2 得 G ( x , x − 1 / 2 ) = 1 1 − x − x G(x,x^{-1/2})=\dfrac{1}{1-\sqrt{x}-x} G(x,x−1/2)=1−x−x1,则 ∑ i = 0 m ( i + m 2 i ) = [ x m ] 1 1 − x − x = [ z 2 m ] 1 1 − z − z 2 = F 2 m + 1 \sum\limits_{i=0}^m\dbinom{i+m}{2i}=[x^m]\dfrac{1}{1-\sqrt{x}-x}=[z^{2m}]\dfrac{1}{1-z-z^2}=F_{2m+1} i=0∑m(2ii+m)=[xm]1−x−x1=[z2m]1−z−z21=F2m+1。其中 1 1 − z − z 2 \frac{1}{1-z-z^2} 1−z−z21 正是斐波那契数列的生成函数除去一个 z z z。