# 错排

错排是指一个集合的排列，其中没有任何元素留在原来的位置上，也就是说，没有不动点的排列。对于含 n 个元素的集合，错排的数目记作 !n（n 的子阶乘），也称为第 n 个相遇数或德蒙莫尔数。<sup>[1](https://mathworld.wolfram.com/Derangement.html)</sup><sup> • </sup><sup>[2](https://oeis.org/A000166)</sup> 计数错排的问题由皮埃尔·雷蒙·德·蒙莫尔（Pierre Rémond de Montmort）于 1708 年提出，称为“相遇问题”（le problème de rencontre），与一种纸牌游戏有关，后来成为概率论的经典问题之一。<sup>[3](https://mathshistory.st-andrews.ac.uk/Extras/Montmort_Treize/)</sup>

| 关键事实 | 详情 |
|---|---|
| 定义 | {1, …, n} 的一个排列 π，满足对每个 i 都有 π(i) ≠ i；等价地说，是没有长度为 1 的循环的排列<sup>[1](https://mathworld.wolfram.com/Derangement.html)</sup><sup> • </sup><sup>[4](https://www.finanz.math.tugraz.at/~prodinger/derangements.pdf)</sup> |
| 计数公式 | !n = n! ∑_{k=0}^{n} (−1)^k / k! = ⌊(n! + e − 2)/e⌋<sup>[1](https://mathworld.wolfram.com/Derangement.html)</sup><sup> • </sup><sup>[5](https://dlmf.nist.gov/26.13)</sup> |
| 递推关系 | d(n) = (n − 1)[d(n − 1) + d(n − 2)] 以及 d(n) = n·d(n − 1) + (−1)^n，其中 d(1) = 0，d(2) = 1<sup>[1](https://mathworld.wolfram.com/Derangement.html)</sup> |
| 最初几项 | 0, 1, 2, 9, 44, 265, 1854, …（OEIS A000166）<sup>[1](https://mathworld.wolfram.com/Derangement.html)</sup><sup> • </sup><sup>[2](https://oeis.org/A000166)</sup> |
| 极限概率 | 随着 n 增大，错排占所有排列的比例趋于 1/e ≈ 0.368，且当 n = 4 时已经非常接近<sup>[1](https://mathworld.wolfram.com/Derangement.html)</sup> |
| 起源 | 由蒙莫尔于 1708 年提出（相遇问题，以 n = 13 的形式提出，称为“十三问题”）；在其《赌博游戏分析论》1713 年第二版中解决<sup>[3](https://mathshistory.st-andrews.ac.uk/Extras/Montmort_Treize/)</sup><sup> • </sup><sup>[1](https://mathworld.wolfram.com/Derangement.html)</sup> |
| 实际应用 | 基本的“秘密圣诞老人”抽签——任何人都不能抽到自己的名字——就是一个均匀随机的错排<sup>[6](https://www.agentcalc.com/secret-santa-generator)</sup> |

## 错排的计数

错排的数目可由容斥原理推出。设 A_i 为固定元素 i 的排列所构成的集合；错排就是不在任何这些集合中的排列。以交替符号求和可得<sup>[7](https://appliedcombinatorics.org/book/s_inclusion-exclusion_derangements.html)</sup>

\[ d_n = \sum_{k=0}^{n} (-1)^k \binom{n}{k} (n-k)! = n! \sum_{k=0}^{n} \frac{(-1)^k}{k!}. \]

对于 n = 5，这给出 120 − 120 + 60 − 20 + 5 − 1 = 44 个错排。<sup>[7](https://appliedcombinatorics.org/book/s_inclusion-exclusion_derangements.html)</sup> 除以 n! 后剩下的是 e^{−1} 的部分和，因此一个随机排列是错排的概率为

\[ \frac{d_n}{n!} = \sum_{k=0}^{n} \frac{(-1)^k}{k!} \;\to\; \frac{1}{e} \quad (n \to \infty). \]

由于截断级数是各项迅速递减的交替级数，对于 n ≥ 1，!n 是 n!/e 的最近整数；NIST 数学函数数字图书馆给出了等价的取整形式 !n = ⌊(n! + e − 2)/e⌋。<sup>[5](https://dlmf.nist.gov/26.13)</sup><sup> • </sup><sup>[1](https://mathworld.wolfram.com/Derangement.html)</sup> 错排数还满足两个简单的递推关系：d(n) = (n − 1)[d(n − 1) + d(n − 2)] 和 d(n) = n·d(n − 1) + (−1)^n，其中 d(1) = 0，d(2) = 1。<sup>[1](https://mathworld.wolfram.com/Derangement.html)</sup>

## 历史

蒙莫尔在其《赌博游戏分析论》（*Essay d'analyse sur les jeux de hazard*，1708）中提出了这个问题，称之为“相遇问题”。在 n = 13 的版本中——称为“十三问题”——庄家翻牌并依次叫出一、二、三，直到十三，只要叫出的数字与翻开的牌不匹配，庄家就赢；蒙莫尔询问的是庄家的期望收益。<sup>[3](https://mathshistory.st-andrews.ac.uk/Extras/Montmort_Treize/)</sup> 《数学百科全书》将他首次考虑匹配问题的时间定在约 1700 年，与一种称为“十三游戏”“相遇游戏”或简称“相遇”的纸牌游戏有关。<sup>[8](https://encyclopediaofmath.org/wiki/Montmort_matching_problem)</sup>

蒙莫尔在《赌博游戏分析论》第二版（1713）中解决了这个问题，其中陈述了一些推广但未予解决；尼古拉·伯努利（Nicolas Bernoulli）独立地用容斥原理解决了它；两人就这个问题进行了大量通信。<sup>[1](https://mathworld.wolfram.com/Derangement.html)</sup><sup> • </sup><sup>[3](https://mathshistory.st-andrews.ac.uk/Extras/Montmort_Treize/)</sup> 后来，莱昂哈德·欧拉（Leonhard Euler，1743，载于《相遇游戏中的概率计算》）、亚伯拉罕·德·莫伊弗尔（Abraham de Moivre，1756，载于《机遇论》）、约翰·兰伯特（Johann Lambert，1773）、爱德华·沃林（Edward Waring，1794）和皮埃尔-西蒙·拉普拉斯（Pierre-Simon Laplace，1812，载于《概率分析理论》）对此问题进行了推广。<sup>[3](https://mathshistory.st-andrews.ac.uk/Extras/Montmort_Treize/)</sup> 欧拉还处理了等价的计数问题：计算一个行列式中不含主对角线元素的项数。<sup>[9](https://encyclopediaofmath.org/wiki/Classical_combinatorial_problems)</sup>

## 匹配问题与帽子检查问题

蒙莫尔匹配问题问的是：给定两个集合 A 和 B 以及它们之间一个已知的双射（例如 n 个丈夫和 n 个妻子），随机配对产生至少一个正确匹配的概率是多少？渐近地，这个概率是 1 − e^{−1}，即错排概率的补。<sup>[8](https://encyclopediaofmath.org/wiki/Montmort_matching_problem)</sup> 传统的课堂版本是帽子检查问题：n 个人寄存帽子，服务员随机归还；没有人收到自己帽子的概率是 d_n/n!，它趋近于 1/e。<sup>[7](https://appliedcombinatorics.org/book/s_inclusion-exclusion_derangements.html)</sup>

同样的计数也是“秘密圣诞老人”礼物交换的基础：每位参与者为随机分配的人买一份礼物，任何人都不能被分配给自己。基本的抽签恰好就是一个随机错排；一旦加入额外限制，比如禁止情侣或室友互相抽中，被计数的对象就变成了带限制位置的排列，而合法的分配可能根本不存在。<sup>[6](https://www.agentcalc.com/secret-santa-generator)</sup> 高效地生成均匀随机错排是一个已解决的算法问题：孔拉多·马丁内斯（Conrado Martínez）、阿洛伊斯·潘霍尔策（Alois Panholzer）和赫尔穆特·普罗丁格（Helmut Prodinger）的算法发表于 2008 年 SIAM ANALCO 会议录，具有期望线性运行时间，可原地运行且只需很少的辅助内存，其行为性质类似于随机排列的费雪-耶茨洗牌。<sup>[10](https://epubs.siam.org/doi/10.1137/1.9781611972986.7)</sup><sup> • </sup><sup>[4](https://www.finanz.math.tugraz.at/~prodinger/derangements.pdf)</sup> 拒绝采样——不断洗牌直到不出现不动点——之所以可行，是因为一个随机排列是错排的概率约为 1/e，所以期望尝试次数约为 e。<sup>[4](https://www.finanz.math.tugraz.at/~prodinger/derangements.pdf)</sup>

## 群论中的错排

在置换群论中，错排是作用在集合上的群中在该集合上没有不动点的元素。卡米尔·若尔当（Camille Jordan）于 1872 年发表的一个经典定理指出，每个非平凡的有限传递置换群都包含一个错排。<sup>[11](https://arxiv.org/abs/2409.01043)</sup> 这一初等事实在数论和拓扑学中有推论，并引出了关于群元素中错排比例 δ(G) 的定量问题。卡梅伦（Cameron）和科恩（Cohen）证明了对于集合 Ω 上的传递群有 δ(G) ≥ |Ω|^{−1}，等号恰好对精确二传递群成立；富尔曼（Fulman）和古拉尔尼克（Guralnick）证明了波士顿-沙莱夫猜想：存在绝对常数 ε > 0，使得每个作为传递置换群的有限单群都满足 δ(G) ≥ ε；对所有充分大的单群可以取 ε = 0.016。<sup>[11](https://arxiv.org/abs/2409.01043)</sup>

错排的比例甚至能刻画完整的对称群。麻省理工学院的数学家比约恩·普嫩（Bjorn Poonen）证明了：如果 S_n 的一个子群 G（或它的一个陪集）与 S_n 本身具有相同比例的无不动点元素，则 G = S_n；对于交错群 A_n 的类似结论在 n ≥ 7 时成立，而在较小的交错群中存在反例，例如 A_5 中一个 10 阶二面体群。<sup>[12](https://londmathsoc.onlinelibrary.wiley.com/doi/10.1112/blms.12639)</sup> 该证明使用了 e 的无理性度量、错排数的整除性质以及本原置换群的界。<sup>[12](https://londmathsoc.onlinelibrary.wiley.com/doi/10.1112/blms.12639)</sup>

## 推广

带参数 r 的相遇数计数恰好有 r 个不动点的排列；错排数是 r = 0 的情形，而恰好有 k 个不动点的排列数为 C(n, k)·d_{n−k}。<sup>[13](https://arxiv.org/abs/1711.04537)</sup><sup> • </sup><sup>[14](https://web.math.utk.edu/~cwagner/papers/comb.pdf)</sup> 匹配问题更一般地问的是 D_{nr}，即第二副 n 张牌与第一副牌恰好产生 r 个匹配的排列数，这个问题催生了研究带限制位置排列的组合数学分支。<sup>[9](https://encyclopediaofmath.org/wiki/Classical_combinatorial_problems)</sup> 其他方向包括 q-模拟：在有限域上，对角线为零的可逆 n × n 矩阵构成错排的 q-模拟，对此已有封闭的计数公式。<sup>[15](https://www.arxiv.symmetricfunctions.com/paper/1011.4539v3)</sup>

## References

1. [Derangement, Wolfram MathWorld](https://mathworld.wolfram.com/Derangement.html)
2. [A000166: Subfactorial or rencontres numbers, OEIS](https://oeis.org/A000166)
3. [Montmort's Problême du Treize, MacTutor History of Mathematics](https://mathshistory.st-andrews.ac.uk/Extras/Montmort_Treize/)
4. [C. Martínez, A. Panholzer, H. Prodinger (2007). Generating Random Derangements](https://www.finanz.math.tugraz.at/~prodinger/derangements.pdf)
5. [DLMF §26.13: Permutations: Cycle Notation, NIST](https://dlmf.nist.gov/26.13)
6. [Secret Santa Generator: Uniform Random Derangements, AgentCalc](https://www.agentcalc.com/secret-santa-generator)
7. [Section 7.4 Derangements, Applied Combinatorics](https://appliedcombinatorics.org/book/s_inclusion-exclusion_derangements.html)
8. [Montmort matching problem, Encyclopedia of Mathematics](https://encyclopediaofmath.org/wiki/Montmort_matching_problem)
9. [Classical combinatorial problems, Encyclopedia of Mathematics](https://encyclopediaofmath.org/wiki/Classical_combinatorial_problems)
10. [Generating Random Derangements, 2008 Proceedings of the Fifth Workshop on Analytic Algorithmics and Combinatorics (ANALCO), SIAM](https://epubs.siam.org/doi/10.1137/1.9781611972986.7)
11. [On derangements in simple permutation groups, arXiv:2409.01043](https://arxiv.org/abs/2409.01043)
12. [B. Poonen (2022). The proportion of derangements characterizes the symmetric and alternating groups, Bulletin of the London Mathematical Society](https://londmathsoc.onlinelibrary.wiley.com/doi/10.1112/blms.12639)
13. [A Short Combinatorial Proof of Derangement Identity, arXiv:1711.04537](https://arxiv.org/abs/1711.04537)
14. [Basic Combinatorics (C. Wagner, University of Tennessee)](https://web.math.utk.edu/~cwagner/papers/comb.pdf)
15. [Matrices with restricted entries and q-analogues of permutations, arXiv](https://www.arxiv.symmetricfunctions.com/paper/1011.4539v3)

---
*Initially written Sep 17, 2026 · Reviewed: Oct 15, 2026 · Edited: Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 物质世界与数学 › 数学与统计学 › 逻辑与离散数学 › General discrete mathematics and discrete structures › Combinatorics › Enumerative combinatorics › Counting techniques and recurrences › Inclusion–exclusion principle

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/derangement

English original: https://www.edgepedia.org/derangement
