组合数学总结

by 段ls

1. 排列与组合

1.1 排列

(1)在没有其他条件的情况下,从 n n n 个不同元素中选取 r r r 个不同的元素的排列数为 A n r = n ! ( n − r ) ! A_{n}^{r} = \frac{n!}{\left( n - r \right)!} Anr=(nr)!n!,当 r > n r>n rn 时, A n r A_{n}^{r} Anr=0

(2)在 n n n 个不同元素中选取 r r r 个元素的圆排列的个数为 A n r r = n ! r ⋅ ( n − r ) ! \frac{A_{n}^{r}}{r} = \frac{n!}{r \cdot \left( n - r \right)!} rAnr=r(nr)!n!

1.2 组合

(1)在在没有其他条件的情况下,从 n n n 个不同元素中选取r个不同的元素的排列数为 C n r = n ! r ! ( n − r ) ! C_{n}^{r} = \frac{n!}{r!\left( n - r \right)!} Cnr=r!(nr)!n!,当 r > n r>n rn 时, C n r C_{n}^{r} Cnr=0

1.3 多重集的排列

(1)设元素 a 1 , a 1 , ⋅ ⋅ ⋅ , a n a_{1},a_{1}, \cdot \cdot \cdot ,a_{n} a1,a1,,an互不相同,从无限多重集 { ∞ ⋅ a 1 , ∞ ⋅ a 2 , ⋅ ⋅ ⋅ ∞ ⋅ a n } \left\{ \infty \cdot a_{1},\infty \cdot a_{2}, \cdot \cdot \cdot \infty \cdot a_{n} \right\} {a1,a2,an}中选取 r r r 个元素的排列数为 n r n^{r} nr

(2)设元素 a 1 , a 1 , ⋅ ⋅ ⋅ , a n a_{1},a_{1}, \cdot \cdot \cdot ,a_{n} a1,a1,,an互不相同,从有限多重集 { K 1 ⋅ a 1 , K 2 ⋅ a 2 , ⋅ ⋅ ⋅ K n ⋅ a n } \left\{ K_{1} \cdot a_{1},K_{2} \cdot a_{2}, \cdot \cdot \cdot K_{n} \cdot a_{n} \right\} {K1a1,K2a2,Knan}中选取 r r r 个元素,当 K 1 ≥ r , K 2 ≥ r , ⋅ ⋅ ⋅ , K n ≥ r , K_{1} \geq r,K_{2} \geq r, \cdot \cdot \cdot ,K_{n} \geq r, K1r,K2r,,Knr,时,排列数为 n r n^{r} nr

(3)设元素 a 1 , a 1 , ⋅ ⋅ ⋅ , a n a_{1},a_{1}, \cdot \cdot \cdot ,a_{n} a1,a1,,an互不相同,有限多重集 { K 1 ⋅ a 1 , K 2 ⋅ a 2 , ⋅ ⋅ ⋅ K n ⋅ a n } \left\{ K_{1} \cdot a_{1},K_{2} \cdot a_{2}, \cdot \cdot \cdot K_{n} \cdot a_{n} \right\} {K1a1,K2a2,Knan}中元素的全排列数为 ( K 1 + K 2 + ⋅ ⋅ ⋅ + K n ) ! K 1 ! K 2 ! ⋅ ⋅ ⋅ K n ! \frac{\left( K_{1} + K_{2} + \cdot \cdot \cdot + K_{n} \right)!}{K_{1}!K_{2}! \cdot \cdot \cdot K_{n}!} K1!K2!Kn!(K1+K2++Kn)!

(4)设元素 a 1 , a 1 , ⋅ ⋅ ⋅ , a n a_{1},a_{1}, \cdot \cdot \cdot ,a_{n} a1,a1,,an互不相同,从有限多重集 { K 1 ⋅ a 1 , K 2 ⋅ a 2 , ⋅ ⋅ ⋅ K n ⋅ a n } \left\{ K_{1} \cdot a_{1},K_{2} \cdot a_{2}, \cdot \cdot \cdot K_{n} \cdot a_{n} \right\} {K1a1,K2a2,Knan}中选取 r r r 个元素,至少存在一个 K i < r K_{i} < r Ki<r时,排列数为 ∑ k 1 + k 2 + ⋅ ⋅ ⋅ + k n = r r ! k 1 ! k 2 ! ⋅ ⋅ ⋅ ⋅ k n ! \sum_{{k_{1} + k_{2} + \cdot \cdot \cdot + k}_{n} = r}^{}\frac{r!}{k_{1}!k_{2}! \cdot \cdot \cdot \cdot k_{n}!} k1+k2++kn=rk1!k2!kn!r!

1.4 多重集的组合

(1)设元素 a 1 , a 1 , ⋅ ⋅ ⋅ , a n a_{1},a_{1}, \cdot \cdot \cdot ,a_{n} a1,a1,,an互不相同,从无限多重集 { ∞ ⋅ a 1 , ∞ ⋅ a 2 , ⋅ ⋅ ⋅ ∞ ⋅ a n } \left\{ \infty \cdot a_{1},\infty \cdot a_{2}, \cdot \cdot \cdot \infty \cdot a_{n} \right\} {a1,a2,an}中选取 r r r 个元素的组合数为 C n + r − 1 r C_{n + r - 1}^{r} Cn+r1r

(2)设元素 a 1 , a 1 , ⋅ ⋅ ⋅ , a n a_{1},a_{1}, \cdot \cdot \cdot ,a_{n} a1,a1,,an互不相同,从有限多重集 { K 1 ⋅ a 1 , K 2 ⋅ a 2 , ⋅ ⋅ ⋅ K n ⋅ a n } \left\{ K_{1} \cdot a_{1},K_{2} \cdot a_{2}, \cdot \cdot \cdot K_{n} \cdot a_{n} \right\} {K1a1,K2a2,Knan}中选取 r r r 个元素,当 K 1 ≥ r , K 2 ≥ r , ⋅ ⋅ ⋅ , K n ≥ r , K_{1} \geq r,K_{2} \geq r, \cdot \cdot \cdot ,K_{n} \geq r, K1r,K2r,,Knr,时,组合数为 C n + r − 1 r C_{n + r - 1}^{r} Cn+r1r

(3)设元素 a 1 , a 1 , ⋅ ⋅ ⋅ , a n a_{1},a_{1}, \cdot \cdot \cdot ,a_{n} a1,a1,,an互不相同,从有限多重集 { K 1 ⋅ a 1 , K 2 ⋅ a 2 , ⋅ ⋅ ⋅ K n ⋅ a n } \left\{ K_{1} \cdot a_{1},K_{2} \cdot a_{2}, \cdot \cdot \cdot K_{n} \cdot a_{n} \right\} {K1a1,K2a2,Knan}中选取 r r r 个元素,至少存在一个 K i < r K_{i} < r Ki<r时,组合数通过容斥定理或生成函数可以求得

1.5 二项式定理

(1) ( a + b ) n = a n + C n 1 a n − 1 b + C n 2 a n − 2 b + ⋅ ⋅ ⋅ + b n = ∑ i = 0 n a n − i b i \left( a + b \right)^{n} = a^{n} + C_{n}^{1}a^{n - 1}b + C_{n}^{2}a^{n - 2}b + \cdot \cdot \cdot + b^{n} = \sum_{i = 0}^{n}{a^{n - i}b^{i}} (a+b)n=an+Cn1an1b+Cn2an2b++bn=i=0nanibi

1.6 鸽巢(抽屉)原理

(1)有 n + 1 n+1 n+1 个物品放到 n n n 个抽屉中,有一个抽屉中至少会有两个物品

1.7* 组合数浅谈

1.7.1 组合数公式

下面是几个组合数公式,可以结合杨辉三角理解

  1. C n k = C n − 1 k − 1 + C n − 1 k C_n^k=C_{n-1}^{k-1}+C_{n-1}^k Cnk=Cn1k1+Cn1k (杨辉恒等式)
  2. C n k = C n n − k C_n^k=C_n^{n-k} Cnk=Cnnk (杨辉三角对称性)
  3. ∑ i = 0 n C n i = 2 n \sum_{i=0}^nC_n^i=2^n i=0nCni=2n (单行和)
  4. ∑ i = 0 n ( C n i ) 2 = C 2 n n \sum_{i=0}^n(C_n^i)^2=C_{2n}^n i=0n(Cni)2=C2nn (单行平方和)
  5. ∑ i = 0 n C k + i k = C n + k + 1 k + 1 \sum_{i=0}^nC_{k+i}^k=C_{n+k+1}^{k+1} i=0nCk+ik=Cn+k+1k+1 (60°斜行和)
  6. F n = { ∑ i = 0 n / 2 − 1 C n / 2 + i 2 i + 1 , n ≡ 0 ( m o d   2 ) ∑ i = 0 ( n − 1 ) / 2 C ( n − 1 ) / 2 + i 2 i , n ≡ 1 ( m o d   2 ) F_n=\begin{cases} \sum_{i=0}^{n/2-1}C_{n/2+i}^{2i+1},n\equiv 0(mod\ 2)\\ \sum_{i=0}^{(n-1)/2}C_{(n-1)/2+i}^{2i},n\equiv 1(mod\ 2)\\ \end{cases} Fn={i=0n/21Cn/2+i2i+1,n0(mod 2)i=0(n1)/2C(n1)/2+i2i,n1(mod 2) (30°斜行和等于斐波那契数列)
  7. C n i = n − i + 1 i C n i − 1 C_n^i=\frac{n-i+1}{i}C_n^{i-1} Cni=ini+1Cni1 (杨辉三角的一行可以递推)

1.7.2 组合数的求法

在ACM竞赛中,我们常常需要计算 C n m % p C_n^m\%p Cnm%p ,可以参考下面几种方法

  1. 如果 n , m n,m n,m 很小(不超过50),可以用C++的库函数 double tgamma(double x) ,这是一个欧拉积分

Γ ( s ) = ∫ 0 + ∞ x s − 1 e − x d x \Gamma(s)=\int_0^{+\infty}x^{s-1}e^{-x}dx Γ(s)=0+xs1exdx

在整数点处的取值满足
Γ ( n + 1 ) = n ! \Gamma(n+1)=n! Γ(n+1)=n!
因此代码可以这么写

ll C(ll n,ll m){
    return (ll)round(tgamma(n+1)/tgamma(m+1)/tgamma(n-m+1));
}

效率并不高,但是对于追求手速来说足够了

  1. 如果 n , m n,m n,m 不大,可以开 O ( n 2 ) O(n^2) O(n2) 的空间,可以利用杨辉恒等式来预处理组合数表
const ll mo=1e9+7;
ll C[1005][1005];
void getC(int n){
    for(int i=0;i<=n;i++){
        for(int j=0;j<=i;j++){
            if(j==0 || j==i)
                C[i][j]=1;
            else
                C[i][j]=(C[i-1][j-1]+C[i-1][j])%mo;
        }
    }
}
  1. 如果 n , m n,m n,m 比较大,可以开 O ( n ) O(n) O(n) 的空间,可以利用前文所述的逆元来求解,当然,要保证 p p p 是素数
const ll mo=1e9+7;
ll C(ll n,ll m){
    static ll M=0,inv[N],mul[N],invMul[N];
    while(M<=n){
        if(M){
            inv[M]=M==1?1:(mo-mo/M)*inv[mo%M]%mo;
            mul[M]=mul[M-1]*M%mo;
            invMul[M]=invMul[M-1]*inv[M]%mo;
        }
        else mul[M]=1,invMul[M]=1;
        M++;
    }
    return mul[n]*invMul[m]%mo*invMul[n-m]%mo;
}

上面的代码中用 O ( n ) O(n) O(n) 的复杂度处理了 [ 1 , n ] [1,n] [1,n] 的逆元,处理 Q Q Q n , m ≤ N n,m\le N n,mN 的询问的总复杂度为 O ( N + Q ) O(N+Q) O(N+Q)

  1. 如果 n , m n,m n,m 更大, p p p 是素数,可以用 L u c a s Lucas Lucas定理来求解

Lucas定理 p p p 是素数,则
C n m = ∏ i = 0 k C n i m i ( m o d   p ) C_n^m=\prod_{i=0}^kC_{n_i}^{m_i} (mod\ p) Cnm=i=0kCnimi(mod p)
其中
n = ∑ i = 0 k n i p i n=\sum_{i=0}^k n_ip^i n=i=0knipi

m = ∑ i = 0 k m i p i m=\sum_{i=0}^k m_ip^i m=i=0kmipi

即将 n , m n,m n,m 表示成 p p p 进制形式

推论
C n m ≡ χ ( n & m = m ) ( m o d   2 ) C_n^m\equiv \chi(n\&m=m)(mod\ 2) Cnmχ(n&m=m)(mod 2)

ll Lucas(ll n,ll m,ll p){
    ll ans=1;
    while(n|m)ans=ans*C(n%P,m%P)%P,n/=P,m/=P;
    return ans;
}
  1. 如果 n n n 固定,可以利用上面的公式7对 m m m 进行递推

2. 容斥原理

2.1 容斥原理

(1)设 A 1 , A 2 , ⋅ ⋅ ⋅ , A n A_{1},A_{2}, \cdot \cdot \cdot ,A_{n} A1,A2,,An是集合 S S S 的子集,表示以集合 S S S 代表可能发生的事件中的 n n n 个子事件, ∣ A i ∣ \left| A_{i} \right| Ai表示子事件 A i A_{i} Ai发生的个数 ( 0 ≤ i ≤ n ) \left( 0 \leq i \leq n \right) (0in),则有
∣ A 1 ∪ A 2 ∪ A 3 ∪ ⋅ ⋅ ⋅ ∪ A n ∣ = ∑ i = 1 n ∣ A i ∣ − ∑ 1 ≤ i < j ≤ n ∣ A i ∩ A j ∣ + ⋅ ⋅ ⋅ + ( − 1 ) n − 1 ∣ A 1 ∩ A 2 ∩ A 3 ∩ ⋅ ⋅ ⋅ ∩ A n ∣ \left| A_{1} \cup A_{2} \cup A_{3} \cup \cdot \cdot \cdot \cup A_{n} \right| = \sum_{i = 1}^{n}\left| A_{i} \right| - \sum_{1 \leq i < j \leq n}^{}\left| A_{i} \cap A_{j} \right| + \cdot \cdot \cdot + \left( - 1 \right)^{n - 1}\left| A_{1} \cap A_{2} \cap A_{3} \cap \cdot \cdot \cdot \cap A_{n} \right| A1A2A3An=i=1nAi1i<jnAiAj++(1)n1A1A2A3An

∣ A 1 ‾ ∩ A 2 ‾ ∩ A 3 ‾ ∩ ⋅ ⋅ ⋅ ∩ A n ‾ ∣ = S − ∣ A 1 ∪ A 2 ∪ A 3 ∪ ⋅ ⋅ ⋅ ∪ A n ∣ \left| \overset{\overline{}}{A_{1}} \cap \overset{\overline{}}{A_{2}} \cap \overset{\overline{}}{A_{3}} \cap \cdot \cdot \cdot \cap \overset{\overline{}}{A_{n}} \right| = S - \left| A_{1} \cup A_{2} \cup A_{3} \cup \cdot \cdot \cdot \cup A_{n} \right| A1A2A3An=SA1A2A3An

2.2 错排问题

(1)设 D n D_{n} Dn表示 1 , 2 , 3 , ⋅ ⋅ ⋅ , n 1,2,3, \cdot \cdot \cdot ,n 1,2,3,,n这n个数的一个排列的错排个数,有
D n = n ! [ 1 − 1 1 ! + 1 2 ! − 1 3 ! + ⋅ ⋅ ⋅ + ( − 1 ) n 1 n ! ] , D 1 = 0 , D 2 = 1 D_{n} = n!\left\lbrack 1 - \frac{1}{1!} + \frac{1}{2!} - \frac{1}{3!} + \cdot \cdot \cdot + \left( - 1 \right)^{n}\frac{1}{n!} \right\rbrack,D_{1} = 0,D_{2} = 1 Dn=n![11!1+2!13!1++(1)nn!1],D1=0,D2=1

D n = ( n − 1 ) [ D n − 1 + D n − 2 ] , n > 2 D_n=(n-1)[D_{n-1}+D_{n-2}],n>2 Dn=(n1)[Dn1+Dn2],n>2

D n = n D n − 1 + ( − 1 ) n D_n=nD_{n-1}+(-1)^n Dn=nDn1+(1)n

2.3 带有禁位的错排问题

(1)n个元素 a 1 , a 2 , a 3 , ⋅ ⋅ ⋅ , a n a_{1},a_{2},a_{3}, \cdot \cdot \cdot ,a_{n} a1,a2,a3,,an带有禁位 X 1 , X 2 , X 3 , ⋅ ⋅ ⋅ , X n X_{1},X_{2},X_{3}, \cdot \cdot \cdot ,X_{n} X1,X2,X3,,Xn的错排数为
P ( X 1 , X 2 , X 3 , ⋅ ⋅ ⋅ , X n ) = n ! − r 1 ( n − 1 ) ! + r 2 ( n − 2 ) ! − ⋅ ⋅ ⋅ + ( − 1 ) k r k ( n − k ) ! + ⋅ ⋅ ⋅ + ( − 1 ) n r n P\left( X_{1},X_{2},X_{3}, \cdot \cdot \cdot ,X_{n} \right) = n! - r_{1}\left( n - 1 \right)! + r_{2}\left( n - 2 \right)! - \cdot \cdot \cdot + \left( - 1 \right)^{k}r_{k}\left( n - k \right)! + \cdot \cdot \cdot + \left( - 1 \right)^{n}r_{n} P(X1,X2,X3,,Xn)=n!r1(n1)!+r2(n2)!+(1)krk(nk)!++(1)nrn
式中 r k r_{k} rk表示有 k k k 个元素在禁位上的个数

3. 特殊计数

3.1 斐波那契数列

(1)满足递推方程 F i = F i − 1 + F i − 2 , i ≥ 3 ; F 1 = F 2 = 1 F_{i} = F_{i - 1} + F_{i - 2},i \geq 3;F_{1} = F_{2} = 1 Fi=Fi1+Fi2,i3;F1=F2=1,的数列 { F n } \left\{ F_{n} \right\} {Fn}称为斐波那契数列, F n F_{n} Fn为斐波那契数。

(2)斐波那契数列的通项公式为 F n = 1 5 [ ( 1 + 5 2 ) n − ( 1 − 5 2 ) n ] F_{n} = \frac{1}{\sqrt{5}}\left\lbrack \left( \frac{1 + \sqrt{5}}{2} \right)^{n} - \left( \frac{1 - \sqrt{5}}{2} \right)^{n} \right\rbrack Fn=5 1[(21+5 )n(215 )n]

(3) F n ≡ 276601605 ( 69150401 3 n − 30849599 7 n ) ( m o d   ( 1 0 9 + 9 ) ) F_n≡276601605(691504013^n-308495997^n)(mod\ (10^9+9)) Fn276601605(691504013n308495997n)(mod (109+9))

3.2 Catalan数

(1)Catalan数满足递推方程 C n = ∑ k = 0 n − 1 C k C n − k − 1 , n ≥ 2 ; C 0 = C 1 = 1 C_{n} = \sum_{k = 0}^{n - 1}{C_{k}C_{n - k-1}},n \geq 2;C_{0} = C_{1} = 1 Cn=k=0n1CkCnk1,n2;C0=C1=1

(2)前几个Catalan数为 1 , 1 , 2 , 5 , 14 , 42 , 132 , 429 , 1430 , 4862 1,1,2,5,14,42,132,429,1430,4862 1,1,2,5,14,42,132,429,1430,4862

(3)Catalan数的通项公式为 C n = C 2 n n n + 1 = C 2 n n − C 2 n n − 1 C_{n} = \frac{C_{2n}^{n}}{n + 1} = C_{2n}^{n} - C_{2n}^{n - 1} Cn=n+1C2nn=C2nnC2nn1

(4)Catalan数的另一个递推公式为 C n = 4 n − 2 n + 1 C n − 1 C_{n} = \frac{4n - 2}{n + 1}C_{n - 1} Cn=n+14n2Cn1

3.3 第一类Stirling数

(1)多项式 [ x ] n = x ( x − 1 ) ( x − 2 ) ⋅ ⋅ ⋅ ( x − n + 1 ) \left\lbrack x \right\rbrack_{n} = x\left( x - 1 \right)\left( x - 2 \right) \cdot \cdot \cdot \left( x - n + 1 \right) [x]n=x(x1)(x2)(xn+1)中常数项和 x , x 2 , x 3 , ⋅ ⋅ ⋅ , x n x,x^{2},x^{3}, \cdot \cdot \cdot ,x^{n} x,x2,x3,,xn的系数称为第一类Stirling数,记为 S 1 ( n , k ) , k = 0 , 2 , ⋅ ⋅ ⋅ , n S_{1}\left( n,k \right),k = 0,2, \cdot \cdot \cdot ,n S1(n,k),k=0,2,,n

(2)第一类Stirling数满足 S 1 ( n , n ) = 1 ; S 1 ( n , 0 ) = 0 ; S 1 ( n , n − k ) = ( − 1 ) n M k n , k = 1 , 2 , ⋅ ⋅ ⋅ , n − 1 S_{1}\left( n,n \right) = 1;S_{1}\left( n,0 \right) = 0;S_{1}\left( n,n - k \right) = \left( - 1 \right)^{n}M_{k}^{n},k = 1,2, \cdot \cdot \cdot ,n - 1 S1(n,n)=1;S1(n,0)=0;S1(n,nk)=(1)nMkn,k=1,2,,n1

式中 M k n M_{k}^{n} Mkn表示 { 1 , 2 , ⋅ ⋅ ⋅ , n − 1 } \left\{ 1,2, \cdot \cdot \cdot ,n - 1 \right\} {1,2,,n1}中任意k个不同的自然数乘积之和。

(3)第一类Stirling数满足递归关系 { S 1 ( n + 1 , k ) = S 1 ( n , k − 1 ) − n S 1 ( n , k ) , n ≥ 0 , k > 0 S 1 ( n , n ) = 1 , S 1 ( n , 0 ) = 0 \left\{ \begin{matrix} S_{1}\left( n + 1,k \right) = S_{1}\left( n,k - 1 \right) - nS_{1}\left( n,k \right),n \geq 0,k > 0 \\ S_{1}\left( n,n \right) = 1,S_{1}\left( n,0 \right) = 0 \\ \end{matrix} \right. {S1(n+1,k)=S1(n,k1)nS1(n,k),n0,k>0S1(n,n)=1,S1(n,0)=0

3.4 第二类Stirling数

定义: S ( n , k ) S(n,k) S(n,k)表示将 n n n个数字分为 k k k个无区别非空集合的方案数。

  • 多项式 [ x ] n = x ( x − 1 ) ( x − 2 ) ⋅ ⋅ ⋅ ( x − n + 1 ) \left\lbrack x \right\rbrack_{n} = x\left( x - 1 \right)\left( x- 2 \right) \cdot \cdot \cdot \left( x - n + 1 \right) [x]n=x(x1)(x2)(xn+1) x n = ∑ k = 0 n S 2 ( n , k ) [ x ] k x^{n} = \sum_{k = 0}^{n}{S_{2}\left( n,k \right)\left\lbrack x \right\rbrack_{k}} xn=k=0nS2(n,k)[x]k,称 S 2 ( n , k ) S_{2}\left( n,k \right) S2(n,k)为第二类Stirling数。
  • S 2 ( n , k ) = 1 k ! ∑ i = 0 k − 1 ( − 1 ) i C k i ( k − i ) n S_{2}\left( n,k \right) = \frac{1}{k!}\sum_{i = 0}^{k- 1}{\left( - 1 \right)^{i}C_{k}^{i}\left( k - i \right)^{n}} S2(n,k)=k!1i=0k1(1)iCki(ki)n
  • 递归关系
    { S 2 ( n + 1 , k ) = S 2 ( n , k − 1 ) + k S 2 ( n , k ) , n ≥ 0 , k ≥ 1 S 2 ( 0 , 0 ) = 1 , S 2 ( n , 0 ) = 0 \left\{ \begin{matrix} S_{2}\left( n+1,k \right) = S_{2}\left( n,k - 1 \right) + kS_{2}\left( n,k \right),n \geq 0,k \geq 1 \\ S_{2}\left( 0,0 \right) = 1,S_{2}\left( n,0 \right) = 0 \\ \end{matrix} \right. {S2(n+1,k)=S2(n,k1)+kS2(n,k),n0,k1S2(0,0)=1,S2(n,0)=0
  • 可以用卷积的方法求第二类Stirling数,可以得到得 S 2 ( n , k ) = ∑ i = 0 k − 1 ( − 1 ) i i ! ( k − i ) n ( k − i ) ! S_2(n,k)=\sum_{i=0}^{k-1}\frac{(-1)^i}{i!}\frac{(k-i)^n}{(k-i)!} S2(n,k)=i=0k1i!(1)i(ki)!(ki)n ,对 a i = ( − 1 ) i i ! a_i=\frac{(-1)^i}{i!} ai=i!(1)i b i = i n i ! b_i=\frac{i^n}{i!} bi=i!in 卷积即可
  • k n = ∑ i = 1 k ( i k ) S ( n , i ) i ! k^n=∑_{i=1}^k(^k_i)S(n,i)i! kn=i=1k(ik)S(n,i)i!

3.5 分拆数

(1)称正整数n分解为r个正整数和的个数为n分解成r的分拆数,记为 P r ( n ) P_{r}\left( n \right) Pr(n)

(2) P 1 ( n ) P_{1}\left( n \right) P1(n)=1 P n ( n ) P_{n}\left( n \right) Pn(n)=1 P n − 1 ( n ) P_{n - 1}\left( n \right) Pn1(n)=1 P n − 2 ( n ) P_{n - 2}\left( n \right) Pn2(n)=2 P n − 3 ( n ) P_{n - 3}\left( n \right) Pn3(n)=3

(3) P 2 ( n ) = ⌈ n − 1 2 ⌉ , n ≥ 2 P_{2}\left( n \right) = \left\lceil \frac{n - 1}{2} \right\rceil,n \geq 2 P2(n)=2n1,n2

(4) P r ( n ) = P 1 ( n − r ) + P 2 ( n − r ) + ⋅ ⋅ ⋅ + P r ( n − r ) P_{r}\left( n \right) = P_{1}\left( n - r \right) + P_{2}\left( n - r \right) + \cdot \cdot \cdot + P_{r}\left( n - r \right) Pr(n)=P1(nr)+P2(nr)++Pr(nr)

3.6 分装问题

将n个球放入r个盒子称为分装问题

(1)相同球和相同盒子,n≥r

①没有空盒子: P r ( n − r ) P_{r}\left( n - r \right) Pr(nr)

②可以有空盒子: ∑ k = 1 r P k ( n ) \sum_{k = 1}^{r}{P_{k}\left( n \right)} k=1rPk(n)

(2)相同球和不同盒子

①没有空盒子: C n − 1 r − 1 C_{n - 1}^{r - 1} Cn1r1

②可以有空盒子: C n + r − 1 n C_{n + r - 1}^{n} Cn+r1n

(3)不同球和相同盒子

①没有空盒子: S 2 ( n , r ) S_{2}\left( n,r \right) S2(n,r)

②可以有空盒子: ∑ k = 1 r S 2 ( n , k ) \sum_{k = 1}^{r}{S_{2}\left( n,k \right)} k=1rS2(n,k)

(4)不同球和不同盒子

①没有空盒子: r ! S 2 ( n , r ) r!S_{2}\left( n,r \right) r!S2(n,r)

②可以有空盒子: r n r^{n} rn

4. 生成函数

4.1 生成函数

对于一个序列 { a i } \left\{ a_{i} \right\} {ai},如果这个序列的每一项 a i a_{i} ai是幂函数 ∑ i = 0 ∞ a i x i \sum_{i = 0}^{\infty}a_{i}x^{i} i=0aixi中各不同的 x i x^{i} xi的系数,称幂函数 ∑ i = 0 ∞ a i x i \sum_{i = 0}^{\infty}a_{i}x^{i} i=0aixi是序列 { a i } \left\{ a_{i} \right\} {ai}的生成函数,也称为母函数。

4.2 指数生成函数

对于一个序列 { a i } \left\{ a_{i} \right\} {ai},如果这个序列的每一项 a i a_{i} ai是幂函数 ∑ i = 0 ∞ a i x i i ! \sum_{i = 0}^{\infty}a_{i}\frac{x^{i}}{i!} i=0aii!xi中各不同的 x i x^{i} xi的系数,称幂函数 ∑ i = 0 ∞ a i x i i ! \sum_{i = 0}^{\infty}a_{i}\frac{x^{i}}{i!} i=0aii!xi是序列 { a i } \left\{ a_{i} \right\} {ai}的指数生成函数。

4.3 利用生成函数求有限多重集的组合

设元素 a 1 , a 1 , ⋅ ⋅ ⋅ , a n a_{1},a_{1}, \cdot \cdot \cdot ,a_{n} a1,a1,,an互不相同,从有限多重集 { K 1 ⋅ a 1 , K 2 ⋅ a 2 , ⋅ ⋅ ⋅ K n ⋅ a n } \left\{ K_{1} \cdot a_{1},K_{2} \cdot a_{2}, \cdot \cdot \cdot K_{n} \cdot a_{n} \right\} {K1a1,K2a2,Knan}中选取r个元素,至少存在一个 K i < r K_{i} < r Ki<r时,求其组合。

F i = 1 + x + x 2 + ⋅ ⋅ ⋅ + x K i , i = 1 , 2 , ⋅ ⋅ ⋅ , n F_{i} = 1 + x + x^{2} + \cdot \cdot \cdot + x^{K_{i}},i = 1,2, \cdot \cdot \cdot ,n Fi=1+x+x2++xKi,i=1,2,,n ∏ i = 1 n F i \prod_{i = 1}^{n}F_{i} i=1nFi x r x^{r} xr的系数即为所求,这里可能需要快速傅里叶变换

4.4 利用指数生成函数求有限多重集的排列

设元素 a 1 , a 1 , ⋅ ⋅ ⋅ , a n a_{1},a_{1}, \cdot \cdot \cdot ,a_{n} a1,a1,,an互不相同,从有限多重集 { K 1 ⋅ a 1 , K 2 ⋅ a 2 , ⋅ ⋅ ⋅ K n ⋅ a n } \left\{ K_{1} \cdot a_{1},K_{2} \cdot a_{2}, \cdot \cdot \cdot K_{n} \cdot a_{n} \right\} {K1a1,K2a2,Knan}中选取r个元素,至少存在一个 K i < r K_{i} < r Ki<r时,求其排列。

F i = 1 + x 1 ! + x 2 2 ! + ⋅ ⋅ ⋅ + x K i K i ! , i = 1 , 2 , ⋅ ⋅ ⋅ , n F_{i} = 1 + \frac{x}{1!} + \frac{x^{2}}{2!} + \cdot \cdot \cdot + \frac{x^{K_{i}}}{K_{i}!},i = 1,2, \cdot \cdot \cdot ,n Fi=1+1!x+2!x2++Ki!xKi,i=1,2,,n ∏ i = 1 n F i \prod_{i = 1}^{n}F_{i} i=1nFi x r x^{r} xr的系数 ∑ k 1 + k 2 + ⋅ ⋅ ⋅ + k n = r r ! k 1 ! k 2 ! ⋅ ⋅ ⋅ ⋅ k n ! \sum_{{k_{1} + k_{2} + \cdot \cdot \cdot + k}_{n} = r}^{}\frac{r!}{k_{1}!k_{2}! \cdot \cdot \cdot \cdot k_{n}!} k1+k2++kn=rk1!k2!kn!r!即为所求

5. 线性递推数列

5.1线性递推方程

F n − b 1 F n − 1 − b 2 F n − 2 − … − b k F n − k = 0 F_{n} - b_{1}F_{n - 1} - b_{2}F_{n - 2} - \ldots - b_{k}F_{n - k} = 0 Fnb1Fn1b2Fn2bkFnk=0

其通项公式为
F n = c 1 q 1 n + c 2 q 2 n + … + c k q k n F_{n} = c_{1}q_{1}^{n} + c_{2}q_{2}^{n} + \ldots + c_{k}q_{k}^{n} Fn=c1q1n+c2q2n++ckqkn
其中 q 1 , q 2 , … , q k q_{1},q_{2},\ldots,q_{k} q1,q2,,qk是特征方程
q k − b 1 q k − 1 − b 2 q k − 2 − … − b k = 0 q^{k} - b_{1}q^{k - 1} - b_{2}q^{k - 2} - \ldots - b_{k} = 0 qkb1qk1b2qk2bk=0
的根

c 1 , c 2 , … , c k c_{1},c_{2},\ldots,c_{k} c1,c2,,ck是常数,由初值条件决定

5.2 非线性递推方程

F n − b 1 F n − 1 − b 2 F n − 2 − … − b k F n − k = S ( n ) F_{n} - b_{1}F_{n - 1} - b_{2}F_{n - 2} - \ldots - b_{k}F_{n - k} = S\left( n \right) Fnb1Fn1b2Fn2bkFnk=S(n)

其通项公式为
F n = c 1 q 1 n + c 2 q 2 n + … + c k q k n + f n F_{n} = c_{1}q_{1}^{n} + c_{2}q_{2}^{n} + \ldots + c_{k}q_{k}^{n} + f_{n} Fn=c1q1n+c2q2n++ckqkn+fn
其中 q 1 , q 2 , … , q k , c 1 , c 2 , … , c k q_{1},q_{2},\ldots,q_{k},c_{1},c_{2},\ldots,c_{k} q1,q2,,qk,c1,c2,,ck与上文相同, f n f_{n} fn为一特解

注:这只是给出了递推方程的一种求通解的理论方法,实际上高次多项式求根以及求递推方程的特解往往是很困难的,在ACM中,若要计算线性递推数列第n项的值,常用矩阵快速幂求解

6. Polya计数

6.1 Burnside 定理

非等价着色数等于置换群中保持不变的着色的平均数
N ( G , C ) = 1 ∣ G ∣ ∑ f ∈ G C ( f ) N(G,C)=\frac{1}{|G|}\sum_{f\in G}C(f) N(G,C)=G1fGC(f)

6.2 Polya计数公式

∣ C ( f ) ∣ = k # f |C(f)|=k^{\#f} C(f)=k#f

你可能感兴趣的:(ACM中的数学问题合集)