对于 $1$ 到 $n$ 的一个排列,用 $mathsf{LIS}$ 表示其最长上升子序列的长度,用 $mathsf{LDS}$ 表示其最长下降子序列的长度。输出一个使得 $mathsf{LIS} + mathsf{LDS}$ 最小的排列。
分析
这道题是 CF Round 502 的 C 题。比赛时我毫无思路,过了 D 题之后,面对 C 束手无策,非常难受。下面来仔细说一说「如何思考这个问题」。
观察样例可以看出一种「使得 $mathsf{LIS} + mathsf{LDS}$ 比较小」的排列模式(pattern)。
将 $1$ 到 $n$ 分成 $k$ 组,每一组都单调递增,第 $i$ 组的最小值大于第 $i+1$ 组的最大值;比如 $n= 9$,7,8,9|4,5,6|1,2,3 就是一个满足上述条件的排列,8,9|5,6,7|1,2,3,4 也是。设第 $i$ 组有 $a_i$ 个数,则 $mathsf{LIS} = max_{i =1}^{k} a_k$,$mathsf{LDS} = k$ 。
当划分的组数 $k$ 确定时,显然 $mathsf{LIS}$ 的最小值为 $lceil n/k ceil$ 。于是问题化为 $arglimits_kmin k + lceil n/k ceil $ 。暴力枚举 $k$ 即可。前已说明,这并不一定是最优解,只是一个上界。
题外话
对于任意正整数 $n$ ,$k + lceil n/k ceil $($k$ 是正整数)一定是在 $k = lfloor sqrt{n} floor$ 处取到最小值吗?
试证明,对任意整数 $n$ 有 $ n/ lfloor sqrt{n} floor = lceil sqrt{n} ceil $, $ n/ lceil sqrt{n} ceil = lfloor sqrt{n} floor $
自然的,现在我们要考虑的问题是
是否存在一个排列满足 $mathsf{LIS} < lceil frac{n}{mathsf{LDS}} ceil $?
这个问题也可以表述为
是否存在一个排列满足 $mathsf{LDS} < lceil frac{n}{mathsf{LIS}} ceil $?
因为将排列首尾翻转以后,$mathsf{LIS}$ 与 $mathsf{LDS}$ 就互换了。
如果我们能证明这样的排列不存在,那么就证明了上面求出的上界亦是下界。
我们将证明这样的排列确实不存在。
前置知识
-
偏序集(partially ordered set,poset)
-
链 (chain),反链(antichain)
Dilworth 定理
For any finite partially ordered set, there exists an antichain $A$, and a partition of the order into a family $P$ of chains, such that the number of chains in the partition equals the cardinality of $A$.
Notes:定理中所谓「a partition of the order」即「a partition of the poset」。
若某条反链 $A$ 与某个链划分 $P$ 大小(cardinality)相等,必然有
- $A$ 是偏序集中的一条最长反链。
- $P$ 是偏序集的最小链划分。
证明:对于任意一个链划分 $P$,设 $C$ 是其中的一条链,则 $A$ 中至多有一个元素来自于链 $C$ 。也就是说,对于任意反链 $A$ 和任意链划分 $P$,有 $|A| le |P|$ 。
因此,Dilworth 定理也可表述为
任意有限偏序集的最长反链的长度,等于其最小链划分中链的个数。
Note:所谓「链/反链的长度」是指其中的元素个数。
Dilworth 定理与我们要证明的东西有什么联系呢?
我们可以从一个排列构造出一个偏序集:
设 $a_1, a_2, dots, a_n$ 是一个 $1$ 到 $n$ 的排列,在集合 $S := {1, 2, dots, n}$ 上定义偏序:$i prec j$ 当且仅当 $i < j$ 且 $a_i < a_j$。于是偏序集 $S$ 里的最长链的长度即 $mathsf{LIS}$,最长反链的长度即 $mathsf{LDS}$。对于 $S$ 的任意链划分 $P$,有 $mathsf{LIS} ge ext{「$P$ 里的最长链的长度」} ge lceil frac{n}{|P|}
ceil$,又因为存在链划分 $P$ 使得 $|P| = ext{「最长反链的长度」}$,于是有 $mathsf{LIS} ge lceil frac{n}{mathsf{LDS}}
ceil$ 。
Erdős–Szekeres theorem
任给两正整数 $r, s$,任意长度为 $(r − 1)(s − 1) + 1 $,由互异的实数构成的序列或者包含一个长为 $r$ 的单调递增序列,或者包含一个长为 $s$ 的单调递减序列。
这个定理的表述真是拗口。
References
https://codeforces.com/blog/entry/61081?#comment-450158