第 6 章 容斥原理及应用
错位排序的一些结论
递推公式
常数
可以使用上面的递推公式求出来错位排序常用的一些数值,
验算代码
#include <iostream>
using namespace std;
int main()
{
int p = 0, q = 1;
int n;
scanf("%d", &n);
for(int i = 3; i <= n; ++ i) {
int tmp = (i-1)*(p+q);
printf("D%d = %d\n", i, tmp);
p = q;
q = tmp;
}
return 0;
}
EX1
Find the number of integers between 1 and 10,000 inclusive that are not divisible by 4,5, or 6.
本题写的详细些,后面类似的题目就不再解释太多细节。
设
计算集合大小时采用向下取整,例如
set | size |
---|---|
2500 | |
2000 | |
1666 | |
500 | |
833 | |
333 | |
166 |
EX2
Find the number of integers between 1 and 10,000 inclusive that are not divisible by 4, 6, 7, or 10.
验证代码
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int cnt = 0;
vector<int> arr{4, 6, 7, 10};
for(int i = 1; i <= 10000; ++ i) {
bool flag = true;
for(auto item: arr) {
if(i%item == 0) {
flag = false;
break;
}
}
if(flag) {
printf("%d ", i);
cnt ++;
if(cnt % 20 == 0) printf("\n");
}
}
printf("\nTotal number = %d\n", cnt);
return 0;
}
EX3
Find the number of integers between 1 and 10,000 that are neither perfect squares nor perfect cubes.
既是完全平方数也是完全立方数的数一定能拆分成 6 个相同数的乘积。
计算满足
set | size |
---|---|
100 | |
21 | |
4 |
EX4
Determine the number of 12-combinations of the multiset
多重集合的组合与方程的非负整数解个数等价,因此满足
的方程
设
求满足
此时方程的解个数为
求满足
此时方程的解个数为
因此可以求出
set | size |
---|---|
120 | |
165 | |
120 | |
84 | |
20 | |
10 | |
4 | |
20 | |
10 | |
4 | |
0 | |
0 | |
0 | |
0 | |
0 |
EX5
Determine the number of 10-conbiations of the multiset
本题和上一题的区别就在于
set | size |
---|---|
0 | |
0 | |
0 | |
0 |
EX6
A bakery sells chocolate, cinnamon, and plain doughnuts and at a particular time has 6 chocolate, 6 cinnamon, and 3 plain. If a box contains 12 doughnuts, how many different options are there for a box of oughnuts?
该问题可以转化为方程
在
定义
set | size |
---|---|
0 | |
0 |
EX7
Determine the number of solutions of the equation
in nonnegative integers , and not exceeding 8.
本题可以利用对称性减少计算,
EX8
Determine the number of solutions of the equation
in positive integers , and not exceeding 5.
类似上一题,不过本题强调正(positive)整数,取值范围因此是
EX9 👻
Determine the number of integral solutions of the equation
that satisfy
过程略,答案 96。
EX10
Let S be a multiset with k distinct objects with given repetition numbers
, respectively. Let r be a positive integer such that there is at least one r-combination of S. Show that, in applying the inclusion-exclusion principle to determine the number of r-combinations of S, one has .
多重集合 r 组合问题转化为方程
假设存在一组解,因此有
当
CAUTION
本题的奇怪之处就在于题目没告诉这些
EX11
Determine the number of permutations of {1, 2, ... ,8} in which no even integer is in its natural position.
EX12
Determine the number of permutations of {1, 2, ... ,8} in which exactly four integers are in their natural positions.
选出 4 个数放入自然位置,剩余 4 个数进行错位排序。
因此总排列数为,
提示
n 元素错位排序可以直接使用公式,
EX13
Determine the number of permutations of {1, 2, ... ,9} in which at least one odd integer is in its natural position.
设
set | size |
---|---|
提示
本题考查定理 6.1.2(正文 p102)至少具有性质的计数。大多数题目还是考察定理 6.1.1 不具有性质的容斥原理。
EX14
Determine a general formula for the number of permutations of the set {1, 2, ... , n} in which exactly k integers are in their natural positions.
选 k 个放到自然位置,其余 n-k 个进行错位排序。
EX15
At a party, seven gentlemen check their hats. In how many ways can their hats be returned so that (a) no gentleman receives his own hat? (b) at least one of the gentlemen receives his own hat? (c) at least two of the gentlemen receive their own hats?
EX15Q(a)
进行错位排序,
EX15Q(b)
全排序减去错位排序(没有人在自然位置),即至少有一个在自然位置。
EX15Q(c)
从上一问的结果(至少有一人在自然位置)中减去恰有一人在自然位置的情况,即至少有两人在自然位置,
EX16
Use combinatorial reasoning to derive the identity
(Here,
is defined to be 1.)
记
全排列
NOTE
本题定义了
EX17
Determine the number of permutations of the multiset
where, for each type of letter, the letters of the same type do not appear consecutively. (Thus abbbbcaca is not allowed, but abbbacacb is.)
设
set | size |
---|---|
105 | |
提示
本题是求的多重集合排序问题和上面的多重集合组合问题进行区分。
EX18
Verify the factorial formula
没太看懂这题想干什么,难道是数学归纳法?
EX19
Using the evaluation of the derangement numbers as given in Theorem 6.3.1, provide a proof of the relation
展开合并同类项即可,
将
将
将
综上,等式成立。
EX20
Starting from the formula Dn = nDn- 1 + (_l)n, (n = 2,3,4, ... ), give a proof of Theorem 6.3.1.
使用数学归纳法证明,当
当 n=1 时,1 只能放在自然位置,没有错位排序,所以错位排序数为 0,且
当
符合等式,综上证毕。
EX21
Prove that
is an even number if and only if n is an odd number.
语句 p:n 为奇数;语句 q:
我们先考虑命题二,对于命题二我们验证它的「逆否命题」,若
观察式子
对于命题一,我们采用数学归纳法证明。当 n 为奇数时, 并且当 n=1 时,有
当 n=2k+1(
综上,当 n 为奇数时,命题得证。
因为命题一和命题二均为真,因此可以说,
简评
颇有点压轴题的感觉,证明若 n 为奇数,则
EX22
Show that the numbers
of Section 6.5 can be rewritten in the form
对
综上,证毕。
EX23
(Continuation of Exercise 22.) Use the identity
to prove that
.
提示
该解法需要使用
在之后的展开项中则分别是
EX24
What is the number of ways to place six nonattacking rooks on the 6-by-6 boards with forbidden positions as shown?
设
EX24 Q(a)
显然,
因此,
禁止位置上无法摆放四辆及以上的车,因此,
综上,可以列表,
0 | 1 | 2 | 3 | 4 | 5 | 6 | |
---|---|---|---|---|---|---|---|
1 | 6 | 12 | 8 | 0 | 0 | 0 |
并且计算摆放的方法数。
EX24 Q(b)
0 | 1 | 2 | 3 | 4 | 5 | 6 | |
---|---|---|---|---|---|---|---|
1 | 12 | 54 | 112 | 108 | 48 | 8 |
EX24 Q(c)
将棋盘禁止位分为相互独立的
0 | 1 | 2 | 3 | |
---|---|---|---|---|
1 | 5 | 6 | 1 |
0 | 1 | 2 | |
---|---|---|---|
1 | 3 | 1 |
进而求出
0 | 1 | 2 | 3 | 4 | 5 | 6 | |
---|---|---|---|---|---|---|---|
1 | 8 | 22 | 24 | 9 | 1 | 0 |
EX25
Count the permutations
of {1, 2, 3, 4, 5, 6}, where and .
该问题等价于棋盘问题,可以把不等式转化为每一行(列)限制的序号,本题画出图像后可以发现,有 4 个大小为 1 的禁止块,2 个大小为 2 的禁止块。
从行的角度来思考,最多放置 4 个车,因为只有 4 行有禁止位,所以
对于
0 | 1 | 2 | 3 | 4 | 5 | 6 | |
---|---|---|---|---|---|---|---|
1 | 8 | 20 | 20 | 7 | 0 | 0 |
EX25PS
本题与其他禁止位放车问题的区别是:本题不太容易拆分成几个独立的部分。
EX26
Count the permutations
of {1, 2, 3, 4,5, 6}, where and .
题目转化过程同 EX25,不过这次计算类似 EX24。将棋盘禁止位置划分为
对于每一部分,先计算摆放车可能的种类数,
0 | 1 | 2 | 3 | |
---|---|---|---|---|
1 | 5 | 4 | 0 |
0 | 1 | 2 | 3 | |
---|---|---|---|---|
1 | 4 | 2 | 0 |
0 | 1 | 2 | 3 | 4 | 5 | 6 | |
---|---|---|---|---|---|---|---|
1 | 9 | 26 | 26 | 8 | 0 | 0 |
EX27
A carousel has eight seats, each representing a different animal. Eight girls are seated on the carousel facing forward (each girl ooks at another girl's back). In how many ways can the girls change seats so that each has a different girl in front of her? How does the problem change if all the seats are identical?
设 8 个位置的座位编号分别为
第 i 个女孩分别坐在 i 号座位上,重排后坐到
记
对于
对于
当所有座位都相同时,第一个选择座位的女孩只有 1 种选法,破环后,其余人选法不变,因此排列总数为
EX27PS
参考答案给的符号有些歧义,
EX28
A carousel has eight seats, each representing a different animal. Eight boys are seated on the carousel but facing inward, so that each boy faces another (each boy looks at another boy's front). In how many ways can the boys change seats so that each faces a different boy? How does the problem change if all the seats are dentical?
第 i 个男孩坐在 i 号座位上,重排后坐到
对于
对于
当所有座位都相同时,则变成了换排列,因此排列总数为
EX29
A subway has six stops on its route from its base location. There are 10 people on the subway as it departs its base location. Each person exits the subway at one of its six stops, and at each stop at least one person exits. In how many ways can this happen?
如果没有任何限制,10 个人一共有
EX30
How many circular permutations are there of the multiset
where, for each type of letter, all letters of that type do not appear consecutively?
设
set | size |
---|---|
105 | |
60 | |
280 | |
12 | |
30 | |
20 | |
3 |
顺便一提
参考答案认为一个 d 本身就是所有的 d 连续出现。
Since d appears in the multiset with multiplicity one, it is vacuously true that for any circular permutation of the multiset, all occurrences of d will appear consecutively.
当然,最后解题时还是认为连续最起码要有一前一后的两项才算连续,所谓连续,参考 EX17,甚至本题数据和结果都与这题一致。
EX31
How many circular permutations are there of the multiset
where, for each type of letter, all letters of that type do not appear consecutively?
设
set | size |
---|---|
27720 | |
6930 | |
2520 | |
1260 | |
1260 | |
504 | |
280 | |
168 | |
105 | |
60 | |
42 | |
30 | |
20 | |
$ A_2 \cap A_3 \cap A_4$ | 12 |
6 |
EX32-40 说明 🚧 👻
后面的题目似乎都是 6.5 小结莫比乌斯反演的练习题。
其中 EX32 是关键的 🔑 题目; EX33 是加星题目(*); EX36 是带有禁止位置的放车问题,虽然指明了用 6.5 中的解题方法。但用 EX24 中的方法也能很快做出答案(6 种)。