by 段ls
(1)在没有其他条件的情况下,从 n n n 个不同元素中选取 r r r 个不同的元素的排列数为 A n r = n ! ( n − r ) ! A_{n}^{r} = \frac{n!}{\left( n - r \right)!} Anr=(n−r)!n!,当 r > n r>n r>n 时, 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⋅(n−r)!n!
(1)在在没有其他条件的情况下,从 n n n 个不同元素中选取r个不同的元素的排列数为 C n r = n ! r ! ( n − r ) ! C_{n}^{r} = \frac{n!}{r!\left( n - r \right)!} Cnr=r!(n−r)!n!,当 r > n r>n r>n 时, C n r C_{n}^{r} Cnr=0
(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\} {K1⋅a1,K2⋅a2,⋅⋅⋅Kn⋅an}中选取 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, K1≥r,K2≥r,⋅⋅⋅,Kn≥r,时,排列数为 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\} {K1⋅a1,K2⋅a2,⋅⋅⋅Kn⋅an}中元素的全排列数为 ( 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\} {K1⋅a1,K2⋅a2,⋅⋅⋅Kn⋅an}中选取 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)设元素 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+r−1r
(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\} {K1⋅a1,K2⋅a2,⋅⋅⋅Kn⋅an}中选取 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, K1≥r,K2≥r,⋅⋅⋅,Kn≥r,时,组合数为 C n + r − 1 r C_{n + r - 1}^{r} Cn+r−1r
(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\} {K1⋅a1,K2⋅a2,⋅⋅⋅Kn⋅an}中选取 r r r 个元素,至少存在一个 K i < r K_{i} < r Ki<r时,组合数通过容斥定理或生成函数可以求得
(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+Cn1an−1b+Cn2an−2b+⋅⋅⋅+bn=∑i=0nan−ibi
(1)有 n + 1 n+1 n+1 个物品放到 n n n 个抽屉中,有一个抽屉中至少会有两个物品
下面是几个组合数公式,可以结合杨辉三角理解
在ACM竞赛中,我们常常需要计算 C n m % p C_n^m\%p Cnm%p ,可以参考下面几种方法
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+∞xs−1e−xdx
在整数点处的取值满足
Γ ( 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));
}
效率并不高,但是对于追求手速来说足够了
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;
}
}
}
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,m≤N 的询问的总复杂度为 O ( N + Q ) O(N+Q) O(N+Q)
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=0∏kCnimi(mod p)
其中
n = ∑ i = 0 k n i p i n=\sum_{i=0}^k n_ip^i n=i=0∑knipi
m = ∑ i = 0 k m i p i m=\sum_{i=0}^k m_ip^i m=i=0∑kmipi
即将 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)设 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) (0≤i≤n),则有
∣ 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| ∣A1∪A2∪A3∪⋅⋅⋅∪An∣=i=1∑n∣Ai∣−1≤i<j≤n∑∣Ai∩Aj∣+⋅⋅⋅+(−1)n−1∣A1∩A2∩A3∩⋅⋅⋅∩An∣
∣ 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| ∣∣∣A1∩A2∩A3∩⋅⋅⋅∩An∣∣∣=S−∣A1∪A2∪A3∪⋅⋅⋅∪An∣
(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![1−1!1+2!1−3!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=(n−1)[Dn−1+Dn−2],n>2
D n = n D n − 1 + ( − 1 ) n D_n=nD_{n-1}+(-1)^n Dn=nDn−1+(−1)n
(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(n−1)!+r2(n−2)!−⋅⋅⋅+(−1)krk(n−k)!+⋅⋅⋅+(−1)nrn
式中 r k r_{k} rk表示有 k k k 个元素在禁位上的个数
(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=Fi−1+Fi−2,i≥3;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=51[(21+5)n−(21−5)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)) Fn≡276601605(691504013n−308495997n)(mod (109+9))
(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=0n−1CkCn−k−1,n≥2;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=C2nn−C2nn−1
(4)Catalan数的另一个递推公式为 C n = 4 n − 2 n + 1 C n − 1 C_{n} = \frac{4n - 2}{n + 1}C_{n - 1} Cn=n+14n−2Cn−1
(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(x−1)(x−2)⋅⋅⋅(x−n+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,n−k)=(−1)nMkn,k=1,2,⋅⋅⋅,n−1
式中 M k n M_{k}^{n} Mkn表示 { 1 , 2 , ⋅ ⋅ ⋅ , n − 1 } \left\{ 1,2, \cdot \cdot \cdot ,n - 1 \right\} {1,2,⋅⋅⋅,n−1}中任意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,k−1)−nS1(n,k),n≥0,k>0S1(n,n)=1,S1(n,0)=0
定义: S ( n , k ) S(n,k) S(n,k)表示将 n n n个数字分为 k k k个无区别非空集合的方案数。
(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) Pn−1(n)=1; P n − 2 ( n ) P_{n - 2}\left( n \right) Pn−2(n)=2; P n − 3 ( n ) P_{n - 3}\left( n \right) Pn−3(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)=⌈2n−1⌉,n≥2
(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(n−r)+P2(n−r)+⋅⋅⋅+Pr(n−r)
将n个球放入r个盒子称为分装问题
(1)相同球和相同盒子,n≥r
①没有空盒子: P r ( n − r ) P_{r}\left( n - r \right) Pr(n−r)
②可以有空盒子: ∑ 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} Cn−1r−1
②可以有空盒子: C n + r − 1 n C_{n + r - 1}^{n} Cn+r−1n
(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
对于一个序列 { 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=0∞aixi中各不同的 x i x^{i} xi的系数,称幂函数 ∑ i = 0 ∞ a i x i \sum_{i = 0}^{\infty}a_{i}x^{i} ∑i=0∞aixi是序列 { a i } \left\{ a_{i} \right\} {ai}的生成函数,也称为母函数。
对于一个序列 { 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=0∞aii!xi中各不同的 x i x^{i} xi的系数,称幂函数 ∑ i = 0 ∞ a i x i i ! \sum_{i = 0}^{\infty}a_{i}\frac{x^{i}}{i!} ∑i=0∞aii!xi是序列 { a i } \left\{ a_{i} \right\} {ai}的指数生成函数。
设元素 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\} {K1⋅a1,K2⋅a2,⋅⋅⋅Kn⋅an}中选取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的系数即为所求,这里可能需要快速傅里叶变换
设元素 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\} {K1⋅a1,K2⋅a2,⋅⋅⋅Kn⋅an}中选取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!即为所求
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 Fn−b1Fn−1−b2Fn−2−…−bkFn−k=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 qk−b1qk−1−b2qk−2−…−bk=0
的根
c 1 , c 2 , … , c k c_{1},c_{2},\ldots,c_{k} c1,c2,…,ck是常数,由初值条件决定
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) Fn−b1Fn−1−b2Fn−2−…−bkFn−k=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项的值,常用矩阵快速幂求解
非等价着色数等于置换群中保持不变的着色的平均数
N ( G , C ) = 1 ∣ G ∣ ∑ f ∈ G C ( f ) N(G,C)=\frac{1}{|G|}\sum_{f\in G}C(f) N(G,C)=∣G∣1f∈G∑C(f)
∣ C ( f ) ∣ = k # f |C(f)|=k^{\#f} ∣C(f)∣=k#f