第 4 章 生成排列和组合(下)
IMPORTANT
下篇有仍有许多模棱两可、较为困难且待完善的 🚧 题目, 欢迎各位高手发表意见,提交补充。
EX31
Generate the 3-permutations of {1, 2, 3, 4, 5}.
验证代码如下,结合生成 r 子集代码和求全排列代码。
验证代码
#include <iostream>
#include <vector>
#include <unordered_set>
using namespace std;
void output(vector<int>& vi) {
for(auto it = vi.begin(); it != vi.end(); ++ it) {
printf("%d ", *it);
}
printf("\n");
}
void generatePermutation(vector<int> permList, int n) {
vector<bool> state(n+1, false);
while(true) {
output(permList);
int maxMovVal = -1;
int maxMovIdx = -1;
for(int i = 0; i < n; ++ i) {
// printf("number: %d, state: %d\n", permList[i], (int)state[permList[i]]);
if(!state[permList[i]] && i > 0) { //arrow to left
if(permList[i] > permList[i-1] && permList[i] > maxMovVal) {
maxMovVal = permList[i];
maxMovIdx = i;
}
} else if (!!state[permList[i]] && i < n-1) { //arrow to right
if(permList[i] > permList[i+1] && permList[i] > maxMovVal) {
maxMovVal = permList[i];
maxMovIdx = i;
}
}
}
if(maxMovIdx == -1) break; //no moveable variables
if(!state[maxMovVal]) { //swap with left
swap(permList[maxMovIdx], permList[maxMovIdx-1]);
} else { //swap with right
swap(permList[maxMovIdx], permList[maxMovIdx+1]);
}
//filp the state of number(s) which greater than selected number.
for(int i = 0; i < n; ++ i) {
if(permList[i] > maxMovVal) state[permList[i]] = !state[permList[i]];
}
}
}
void generateRSubset(vector<int>& vi, unordered_set<int>& st, int n, int r) {
// output(vi);
generatePermutation(vi, r);
int k = r-1;
for(; k >= 0; -- k) {
if(vi[k] < n && st.find(vi[k]+1) == st.end()) {
break;
}
}
if(k < 0) return;
int val = vi[k] + 1;
for(int i = k; i < r; ++ i) {
st.erase(vi[i]);
vi[i] = val;
st.insert(vi[i]);
val ++;
}
generateRSubset(vi, st, n, r);
}
int main()
{
int n, r;
printf("Place input the Dictionary size(n) and the Subset size(r):\n");
scanf("%d %d", &n, &r);
vector<int> list;
unordered_set<int> unord_st;
for(int i = 1; i <= r; ++ i) {
list.emplace_back(i);
unord_st.insert(i);
}
generateRSubset(list, unord_st, n, r);
return 0;
}
EX31PS
答案好像只给出了 1 开头的子集(课本定义的集合顺序)。
验证代码感觉有 Bug,但是本着能跑就行的原则,对比答案给出的部分没有差错。
EX32 👻
Generate the 4-permutations of {1, 2, 3, 4, 5, 6}.
同上。
EX33
In which position does the subset 2489 occur in the lexicographic order of the 4-subsets of {1, 2, 3, 4, 5, 6, 7, 8, 9}?
从所有排列中,依次减去 X X X X 型,2 X X X 型,2 4 X X 型和 2 4 8 X 型,确定 2489 所在位置。
EX33PS
带入公式,杨辉三角之外的数全为 0。
后来会知道这些是扩展牛顿二项式。
EX34
Consider the r-subsets of {1, 2, ... , n} in lexicographic order.
(a) What are the first (n - r + 1) r-subsets?
(b) What are the last (r + 1) r-subsets?
EX34Q(a)
显然第一个子集是
EX34Q(b)
容易验证最后一个子集是
EX35
The complement
of an r-subset A of {1, 2, ... , n} is the (n-r)-subset of {1, 2, ... , n}, consisting of all those elements that do not belong to A. Let M = , the number of r-subsets and, at the same time, the number of (n-r)-subsets of {1, 2, ... , n}. Prove that, if are the r-subsets in lexicographic order, then
are the (n-r)-subsets in lexicographic order.
任取两个不同的 r 子集 A 和 B,由集合字典序的定义(正文 p68)知, 如果
由上可知,如果
EX36
Let X be a set of n elements. How many different relations on X are there? How many of these relations are reflexive? Symmetric? Antisymmetric? Reflexive and symmetric? Reflexive and anti-symmetric?
有序对 (a,b) 一共有
自反(reflexive)关系:自反关系必须包含所有的有序对 (a, a),对于剩余的有序对 (x, y)(其中
对称(symmetric)关系:(a, a) 可以任意出现;(x, y) 和 (y, x)(其中
反对称(Antisymmetric)关系: (a, a) 可以任意出现共有 n 个;(x, y) 和 (y, x)(其中
自反且对称:(a, a) 必须都在;(x, y) 和 (y, x)(其中
自反且反对称:(a, a) 必须都在;(x, y) 和 (y, x)(其中
提示
反对称和非对称是两个概念。
EX36 参考链接
离散数学 N 元集合关系个数计算 - 百度文库 (baidu.com)
discrete mathematics and its applications seventh edition section 9.1 47
EX37
Let R' and R" be two partial orders on a set X. Define a new relation R on X by xRy if and only if both xR'y and xR"y hold. Prove that R is also a partial order on X. (R is called the intersection of R' and R".)
证明 R 是 X 上的偏序关系,即证明 R 满足自反性、反对称性和传递性。
自反性:对任意的
反对称性:对于不同的
传递性:
提示
逻辑推理若 p 则 q,若非 q 则非 p, 那由德摩根律,非 q 是指
EX38
Let
and be partially ordered sets. Define a relation T on the set by
Prove that
is a partially ordered set. is called the direct product of and and is also denoted by . More generally, prove that the direct product of partially ordered sets is also a partially ordered set.
自反性:取
反对称性:取
传递性:取
综上,T 满足偏序关系且
显然我们可以取
EX39 🚧
Let
be the partially ordered set with J = {0, 1} and with 0 < 1. By identifying the subsets of a set X of n elements with the n-tuples of 0s and 1s, prove that the partially ordered set can be identified with the n-fold direct product
令
定义
即
所以满足偏序关系
并且有如下等价命题,
- 偏序关系
- 项的关系
- 如果项
,那么一定有 - 如果下标
,那么一定有 - 集合关系
EX39PS
其实答案每一句话都能看懂,就是连在一起感觉没有逻辑。
还有另一种参考,我也是大为震惊(因为看不懂)。
EX40 🚧
Generalize Exercise 39 to the multiset of all combinations of the multiset X =
. (Part of this exercise is to determine the "natural" partial order of these multisets.)
对于任意非负整数 r,定义由
对于
- 在偏序集
中
所以偏序集
EX41 🚧
Show that a partial order on a finite set is uniquely determined by its cover relation.
有限集 X 上的偏序关系
引理:对于不同的
- 存在整数
,并且取自 X 的序列 - 满足
并且 覆盖
先由 1 证 2,考虑取自 X 的序列
因此,我们可以从 S 中选择出大小为 r 的序列,使之满足覆盖条件
再由 2 证 1,因为
综上,有限集上的偏序关系由覆盖关系唯一确定。
EX42 🚧
Describe the cover relation for the partial order
on the collection of an subsets of a set X.
记 n = |X|,所有子集分布在 n 阶立方体上。
EX43
Let X = {a, b, c, d, e, f} and let the relation R on X be defined by aRb, bRc, cRd, aRe, eRf, fRd. Verify that R is the cover relation of a partially ordered set, and determine all the linear extensions of this partial order.
就是写出所有的拓扑排序。
abecfd, abefcd, aebcfd, aebfcd, abcefd, aefbcd.
EX44
Let
be a partition of a set X. Define a relation R on X by xRy if and only if x and y belong to the same part of the partition. Prove that R is an equivalence relation.
自反性:对于任意
对称性:对于
传递性:对于
综上,R 是等价关系。
EX44PS
区分等价关系(自反、对称、传递)和偏序关系(自反、反对称、传递)。
EX45
Define a relation R on the set Z of all integers by aRb if and only if a = ±b. Is R an equivalence relation on Z? If so, what are the equivalence classes?
R 是等价关系,证明如下。
自反性:任意
对称性:任意
传递性:任意
两个等价类,一个等价类只有 0,另一个等价类是正数和它的相反数。
EX46
Let m be a positive integer and define a relation R on the set X of all nonnegative integers by aRb if and only if a and b have the same remainder when divided by m. Prove that R is an equivalence relation on X. How many different equivalence classes does this equivalence relation have?
自反性:对于任意的
因此 R 是等价关系。等价类根据余数划分,一共有 m 个等价类。
EX47 🔑
Let
denote the set of all partitions of the set {1, 2, ... ,n} into nonempty sets. Given two partitions and in , define , provided that each part of is contained in a part of . Thus, the partition can be obtained by partitioning the parts of . This relation is usually expressed by saying that is a refinement of . (a) Prove that the relation of refinement is a partial order on
. (b) By Theorem 4.5.3, we know that there is a one-to-one correspondence between
and the set of all equivalence relations on {1, 2, ... ,n}. What is the partial order on that corresponds to this partial order on ? (c) Construct the diagram of
for n = 1,2,3, and 4.
EX47Q(a)
自反性:对任意
反对称性:对于
传递性:对于
因此加细关系是
EX47Q(b) 🚧
EX47Q(c)
Hasse 图如下所示。
EX48
Consider the partial order
on the set X of positive integers given by "is a divisor of." Let a and b be two integers. Let c be the largest integer such that c a and c b, and let d be the smallest integer such that a d and b d. What are c and d?
并且由偏序关系,可知
EX49
Prove that the intersection
of two equivalence relations Rand S on a set X is also an equivalence relation on X. Is the union of two equivalence relations on X always an equivalence relation?
自反性:取
对称性:取
传递性:取
综上,
可以验证 R 和 S 都是 X 上的等价关系,而
不满足等价关系,因为存在
EX49PS
两个等价关系的并集不满足等价关系,需要从传递性方面反证,因为等价关系的并集自反性和对称性都是满足的。
EX50
Consider the partially ordered set (X,
) of subsets of the set X = {a, b, c} of three elements. How many linear extensions are there?
技术问题,图画了个大概,方框内是集合,与顺序无关。题目需要求拓扑排序的数目。
从空集出发,必须先选择 2 个单元素集(不妨假设选了
第二步则可以考虑选择剩余的单元素集(
或者优先选择双元素集合(
综上,一共有
参考链接
Combinatorics and Linear Extensions - Mathematics Stack Exchange
EX51 🚧 🔑
Let n be a positive integer, and let
be the set of n! permutations of {1, 2, ... ,n} Let and be two permutations in , and define a provided that the set of inversions of is a subset of the set of inversions of . Verify that this defines a partial order on , called the inversion poset. Describe the cover relation for this partial order and then draw the diagram for the inversion poset .
描述覆盖关系:
不知所言的参考答案 💊
定义
覆盖 - 可以从
中翻转 ab 到 ba(a<b)来获得
先由 1 证 2:我们假设
下证,b 与 a 相邻,假设
再由 2 证 1:同上,我们有
除 a 和 b 的坐标外,其余坐标均相同, 显然
画 图 🔑
时间关系,
EX51PS
对比 EX30,求的是字典序的逆序列,与本题所定义的偏序不同。
可以参考一下,Student (jade-cheng.com)。
EX52
Verify that a binary n-tuple
is in place k in the Gray code order list where k is determined as follows: For i = 0,1, ... ,n-1, let Then
Thus,
is in the same place in the Gray code order list of binary n-tuples as is in the lexicographic order list of binary n-tuples.
由题意,
显然,当 k=0 时,
假设当 k=m 时成立,如果
如果如果
EX52PS
Problem B 介绍了二进制的加法(自增 +1)和减法(自减 -1)求法;Problem G 介绍了反射 Gray 码的前驱和后继求法(联系 EX23 和 EX24)。
EX53 🚧
Continuing with Exercise 52, show that
can be recovered from $b_{n-1}\cdots b_1 b_0 $, by and for i = 0,1, ... , n-1,
太迷惑了,以至于没整理。
仍旧采用数学归纳法证明,与上一题类似,
显然,当 k=0 时,
假设当 k=m 时成立,m 所对应的反射 Gray 码为
当
UNFINISHED
又是感觉答案和题目毫无关系。
EX54
Let
be a finite partially ordered set. By Theorem 4.5.2 we know that has a linear extension. Let a and b be incomparable elements of X. Modify the proof of Theorem 4.5.2 to obtain a linear extension of such that . (Hint: First find a partial order on X such that whenever , then and, in addition, .)
对于不可比元素 a 和 b,我们可以通过定义 b 覆盖 a(比如线性顺序列出),来找到 X 上的偏序关系
综上,我们可以找到一种线性扩展,使偏序集
EX54 参考链接
EX55
Use Exercise 54 to prove that a finite partially ordered set is the intersection of all its linear extensions.(see Exercise 37).
由 EX54 的结论可知,对于不可比元素 a 和 b,总能找到一个线性扩展使得
因为
EX55 参考链接
EX56
The dimension of a finite partially ordered set
is the smallest number of its linear extensions whose intersection is . By Exercise 55, every partially ordered set has a dimension. Those that have dimension 1 are the linear orders. Let n be a positive integer and let be a permutation of {1, 2, ... ,n} that is different from 1, 2, ... ,n. Let X = . Now define a relation R on X by if and only if (ordinary integer inequality) and (again ordinary inequality); that is, is not an inversion of . Thus, for instance, if n = 3 and = 2,3,1, then X = {(1, 2), (2, 3), (3, 1)}, and (1,2)R(2, 3), but . Prove that R is a partial order on X and that the dimension of the partially ordered set (X, R) is 2, provided that is not the identity permutation 1,2, ..., n.
易证 R 是 X 上的偏序关系,
自反性:
反对称性:
传递性:
定义 X 上的偏序关系
显然
EX57 🚧
Consider the set of all permutations
of 1,2, ... ,n such that for k = 1,2, ... ,n. (Such permutations are called derangements and are discussed in Chapter 6.) Describe an algorithm for generating a random derangement (modify the algorithm given in Section 4.1 for generating a random permutation).
EX58 🚧
Consider the complete graph
defined in Chapter 2, in which each edge is colored either red or blue. Define a relation on the n points of by saying that one point is related to another point provided that the edge joining them is colored red. Determine when this relation is an equivalence relation, and, when it is, determine the equivalence classes.
R 被定义在完全图的点集
R 可以定义为:
自反性:对于
对称性:对于
传递性:
当
等价类时所有的完全图
WARNING
传递性证明没能完成
EX59
Let
be an integer. Prove that the total number of inversions of all n! permutations of 1,2, ... ,n equals (Hint: Pair up the permutations so that the number of inversions in each pair is n(n - 1)/2.)
第一步,计算逆序可能出现的组合数量:因为逆序是两两配对,逆序组合不超过
因此,所有排列中的逆序总数为