避免 Pattern 的 RDL 计数 - Reliauk
避免 Pattern 的 RDL 计数

避免 Pattern 的 RDL 计数

搬运自 Pattern Avoidance in Reverse Double Lists。

#定义

RDL(Reverse Double List) 是把一个排列的反串拼接在它的后面得到的结构。

  • 具体来说,记长为 $2n$ 的 RDL 构成的集合为 $\mathcal{R}_n$,那么有 $\mathcal R_n = \{ \pi\pi^{\textsf{R}}\mid\pi \in \mathcal S_n \}$,其中 $\mathcal S_n$ 是所有 $n$ 阶排列构成的集合。

避免 Pattern 的 RDL 计数是这样一个问题:

  • 给定我们称之为 Pattern 的一个排列 $\rho$。
  • 考虑满足如下条件的 $n$ 阶 RDL:
    • 不存在大小为 $\lvert \rho \rvert$ 的子序列,满足其中元素的相对大小顺序和 $\rho$ 相等。
  • 满足该条件的 $n$ 阶 RDL 集合被记作 $\mathcal R_n(\rho)$,我们要求的即 $\lvert \mathcal R_n(\rho)\rvert$。

事实上,对于 $\lvert \rho \rvert \leq 4$ 的情形,我们有足够快速简单的方法计算 $\lvert \mathcal R_n(\rho)\rvert$。

由于篇幅有限,下文中的结论并不会给出证明,详细证明可见原论文。

#$\lvert\rho\rvert \leq 3$

$$ \begin{aligned} &\lvert\mathcal R_n(\langle1\rangle)\rvert = 0\\ &\lvert\mathcal R_n(\langle1, 2\rangle)\rvert = \lvert\mathcal R_n(\langle2, 1\rangle)\rvert = \begin{cases} 1 & n = 1\\ 0 & n \geq 2 \end{cases}\\ &\lvert\mathcal R_n(\langle1, 2, 3\rangle)\rvert = \lvert\mathcal R_n(\langle3, 2, 1\rangle)\rvert = \begin{cases} 1 & n = 1\\ 2 & n = 2, 3\\ 0 & n \geq 4 \end{cases}\\ &\lvert\mathcal R_n(\langle1, 3, 2\rangle)\rvert = \lvert\mathcal R_n(\langle2, 3, 1\rangle)\rvert= \lvert\mathcal R_n(\langle3, 1, 2\rangle)\rvert= \lvert\mathcal R_n(\langle2, 1, 3\rangle)\rvert = \begin{cases} 1 & n = 1\\ 2 & n \geq 2 \end{cases} \end{aligned} $$

这一部分的 $\lvert \mathcal R_n(\rho)\rvert$ 都可以被 $\mathcal O(1)$ 计算。

#$\lvert \rho \rvert = 4$

这一部分当 $n$ 较小时,$\lvert\mathcal R_n(\rho)\rvert$ 并没有很好的性质,不过我们可以用 $\mathcal O(n! \cdot \text{poly}(n))$ 的暴力求解。

下表中的式子都是 $n$ 较大时成立的(式子后面标注了成立的范围)。

Pattern $\rho$ $\lvert\mathcal R_n(\rho)\rvert=$
$\langle1,2,3,4\rangle, \langle4,3,2,1\rangle$ $0\qquad(n \geq 7)$
$\langle1,2,4,3\rangle, \langle2,1,3,4\rangle, \langle3,4,2,1\rangle, \langle4,3,1,2\rangle$ $\dfrac{n^3}3-\dfrac{7n}3+4\qquad(n \geq 3)$
$\langle1,3,2,4\rangle, \langle4,2,3,1\rangle, \langle2,1,4,3\rangle, \langle3,4,1,2\rangle$ $2\lvert\mathcal R_{n−1}(\rho)\rvert + 4\qquad(n \geq 4)$
$\langle1,4,2,3\rangle, \langle2,3,1,4\rangle, \langle3,2,4,1\rangle, \langle4,1,3,2\rangle$ $2\lvert\mathcal R_{n−1}(\rho)\rvert + \lvert\mathcal R_{n−3}(\rho)\rvert + 2\qquad(n \geq 5)$
$\langle1,4,3,2\rangle, \langle2,3,4,1\rangle, \langle3,2,1,4\rangle, \langle4,1,2,3\rangle$ $2\lvert\mathcal R_{n−1}(\rho)\rvert + \lvert\mathcal R_{n−2}(\rho)\rvert\qquad(n \geq 5)$
$\langle1,3,4,2\rangle, \langle2,4,3,1\rangle, \langle3,1,2,4\rangle, \langle4,2,1,3\rangle$ $2\lvert\mathcal R_{n−1}(\rho)\rvert + \lvert\mathcal R_{n−2}(\rho)\rvert + 2\qquad(n \geq 4)$
$\langle2,4,1,3\rangle, \langle3,1,4,2\rangle$ $2\lvert\mathcal R_{n−1}(\rho)\rvert + 2\lvert\mathcal R_{n−2}(\rho)\rvert\qquad(n \geq 3)$

对于第一、二行的式子,它们已经是封闭的形式了,我们可以直接 $\mathcal O(1)$ 计算。

其余的式子都是低阶线性递推,可以使用矩阵快速幂 $\mathcal O(\log n)$ 计算。

#总结

综上,对于所有的 $\lvert \rho \rvert \leq 4$,我们都可以以 $\mathcal O(1)$ 或 $\mathcal O(\log n)$ 的时间复杂度计算 $\lvert\mathcal R_n(\rho)\rvert$。

实际使用中,上面的式子不需要记住,只需要把 $n$ 较小的表打出来,去除前面不满足式子的 $\mathcal O(1)$ 项,再作差分或高消系数得到式子即可。注意高消时要考虑这个递推式有常数项。