# 计数

**计数**，在数学中，是指确定一个有限集合的元素个数，或满足给定条件的对象的个数；作为一个研究领域，它被称为枚举组合学。典型的问题是给定一个集合 \( A \)，求其大小 \( |A| \)，例如将 \( n \) 对夫妇安排在一张圆桌旁且每对夫妇坐在一起的方案数，或者将一个正整数 \( n \) 表示为若干正整数之和的方案数。<sup>[1](https://web.stanford.edu/class/cs103x/cs103x-notes.pdf)</sup> 有限集合 \( A \) 的元素个数，即它的基数，是唯一满足存在从 \( A \) 到 \( \{1, 2, \dots, n\} \) 的双射函数的 \( n \)。<sup>[2](https://www.math.colostate.edu/~hulpke/lectures/m501/notes.html)</sup>

| 关键事实 | 详情 |
|---|---|
| 研究对象 | 枚举组合学对集合 \( A \) 的构型进行计数，计算 \( |A| \)。<sup>[1](https://web.stanford.edu/class/cs103x/cs103x-notes.pdf)</sup> |
| 加法原理 | 对于两两不相交的集合，\( \left|\bigcup_{i=1}^{n} A_i\right| = \sum_{i=1}^{n} |A_i| \)。<sup>[1](https://web.stanford.edu/class/cs103x/cs103x-notes.pdf)</sup> |
| 乘法原理 | \( n \) 个依次进行的选择，每个有 \( c_i \) 种选项，共有 \( \prod_{i=1}^{n} c_i \) 种结果；字母不重复的三字母单词数为 \( 26 \cdot 25 \cdot 24 \)。<sup>[1](https://web.stanford.edu/class/cs103x/cs103x-notes.pdf)</sup> |
| 选取公式 | 从 \( n \) 个对象中选取 \( k \) 个：\( n^k \)（有序，可重复），\( (n)_k \)（有序，不可重复），\( \binom{n+k-1}{k} \)（无序，可重复），\( \binom{n}{k} \)（无序，不可重复）。<sup>[2](https://www.math.colostate.edu/~hulpke/lectures/m501/notes.html)</sup> |
| 复杂性 | 复杂度类 \( \#\mathrm{P} \) 由瓦利安特于1979年定义，刻画了计数问题；一个计数问题即使其判定版本很简单，也可能很难。<sup>[3](https://www.researchgate.net/publication/2591186_Counting_Complexity)</sup><sup> • </sup><sup>[4](https://www.cambridge.org/core/books/abs/computational-complexity/complexity-of-counting/8C2E96892F02F64673C12931FCB900CC)</sup> |
| 早期历史 | 组合方法最早约在公元前200年出现于梵语韵律学家平伽拉（Piṅgala）的《韵律经》（Chandaḥsūtra）中。<sup>[5](https://epubs.siam.org/doi/full/10.1137/25M180634X)</sup> |
| 物理关联 | 整数分拆和平面分拆计数统计力学中的晶格结构，其中伊辛模型是主要例子。<sup>[6](https://dlmf.nist.gov/26.20)</sup> |

## 基本原理

大多数计数论证都基于三条基本原理。<sup>[1](https://web.stanford.edu/class/cs103x/cs103x-notes.pdf)</sup>

**加法原理。** 若 \( n \) 个集合 \( A_i \) 两两不相交，即对 \( i \ne j \) 有 \( A_i \cap A_j = \varnothing \)，则它们并集的大小等于各自大小之和。如果有 \( n \) 种方式从第一堆中取一个对象，有 \( m \) 种方式从第二堆中取一个，则总共有 \( n + m \) 种方式。<sup>[1](https://web.stanford.edu/class/cs103x/cs103x-notes.pdf)</sup>

**乘法原理。** 若依次进行 \( n \) 件事，分别有 \( c_1, c_2, \dots, c_n \) 种方式，则行动方案数为 \( \prod_{i=1}^{n} c_i \)。在英文字母表上，每个字母至多出现一次的三字母单词数为 \( 26 \cdot 25 \cdot 24 \)：第一个字母有26种选择，第二个有25种，第三个有24种。<sup>[1](https://web.stanford.edu/class/cs103x/cs103x-notes.pdf)</sup> 同一原理给出笛卡尔积的基数 \( |A \times B| = |A| \cdot |B| \)，而长度为 \( k \) 的序列不过是各分量独立选取的 \( k \) 重笛卡尔积中的一个元素。<sup>[2](https://www.math.colostate.edu/~hulpke/lectures/m501/notes.html)</sup>

**双射原理。** 从 \( A \) 到 \( B \) 的双射存在当且仅当 \( |A| = |B| \)，因此计数 \( A \) 的一种方法是构造一个到已知大小的集合 \( B \) 的双射。<sup>[1](https://web.stanford.edu/class/cs103x/cs103x-notes.pdf)</sup> 将 \( n \) 表示为 \( k \) 个正整数的有序和的方式数正是这样计算的：将 \( n \) 写成 \( 1 + 1 + \cdots + 1 \)，留下 \( n - 1 \) 个加号，选择其中 \( k - 1 \) 个来分隔 \( k \) 个加数，得到 \( \binom{n-1}{k-1} \) 种有序和。若允许加数为零，则计数变为 \( \binom{n+k-1}{k-1} \)。<sup>[2](https://www.math.colostate.edu/~hulpke/lectures/m501/notes.html)</sup>

## 基本计数问题

初等答案由上述原理推出。从 \( k \) 元集合到 \( n \) 元集合的函数个数为 \( n^k \)，可用乘法原理对 \( k \) 归纳证明。<sup>[1](https://web.stanford.edu/class/cs103x/cs103x-notes.pdf)</sup> 从 \( n \) 个对象中选取 \( k \) 个的方式数取决于两个独立的问题：顺序是否重要，以及是否允许重复：<sup>[2](https://www.math.colostate.edu/~hulpke/lectures/m501/notes.html)</sup>

| | 可重复 | 不可重复 |
|---|---|---|
| 顺序重要（序列） | \( n^k \) | \( (n)_k \) |
| 顺序不重要（集合） | \( \binom{n+k-1}{k} \) | \( \binom{n}{k} \) |

这里 \( \binom{n}{k} = \frac{n!}{(n-k)!\,k!} \)，而 \( \binom{n+k-1}{k} \) 计数的是多重集，即同一元素可以多次出现的类集合汇集。<sup>[2](https://www.math.colostate.edu/~hulpke/lectures/m501/notes.html)</sup>

## 双射与双重计数

**间接计数。** 与其直接计数集合 \( A \)，通常更容易建立双射 \( f : A \to B \)，即一个单射且满射的函数；于是 \( |A| = |B| \)，知道 \( |B| \) 就能求出 \( |A| \)。<sup>[2](https://www.math.colostate.edu/~hulpke/lectures/m501/notes.html)</sup>

**双重计数。** 用两种不同方式计数同一集合必然得到相同结果，由此产生的等式往往给出有趣的恒等式。经典例子包括帕斯卡递推 \( \binom{n+1}{k} = \binom{n}{k-1} + \binom{n}{k} \)、恒等式 \( \sum_{k=0}^{n} \binom{n}{k} = 2^n \)，以及 \( \sum_{k=0}^{n} \binom{n}{k}^2 = \binom{2n}{n} \)，最后一个是通过按两种顺序计数带有指定主席的委员会得到的。<sup>[2](https://www.math.colostate.edu/~hulpke/lectures/m501/notes.html)</sup>

## 历史

计数的历史远早于它的形式化。组合方法最早约在公元前200年出现于平伽拉的《韵律经》（“韵律规则”），其中提出了涉及排列和组合的广义技巧，用以说明由轻音节和重音节构成的梵语韵文的各种可能变化。组合规则后来出现在梵语学术的各个领域——音乐、建筑、医学和调香术——并在公元后第一千年的后半叶进入数学论著，如室利陀罗（Śrīdhara）的《算法书》（Pāṭīgaṇita）和大雄（Mahāvīra）的《算法精要》（Gaṇitasārasaṅgraha）。<sup>[5](https://epubs.siam.org/doi/full/10.1137/25M180634X)</sup>

在欧洲，对组合学的首次系统研究见于布莱斯·帕斯卡（Blaise Pascal，1623–1662）和皮埃尔·德·费马（Pierre de Fermat，1601–1665）的著作。<sup>[7](https://bookofproofs.github.io/branches/combinatorics/historical-development-of-combinatorics.html)</sup> 1654年，两人运用组合方法及其他手段解决了来自赌博游戏的理论问题，帕斯卡关于算术三角形的论著或可称为第一部现代组合学论著。<sup>[8](https://academic.oup.com/book/11334/chapter-abstract/159960872)</sup> 分拆计数，即求 \( p(n) \)——将 \( n \) 写成正整数之和且不计顺序的方式数——吸引了持续的努力：欧拉（Euler）计算到了 \( n = 69 \) 的值，19世纪90年代珀西·麦克马洪（Percy MacMahon）编制了直到 \( p(200) = 3{,}972{,}999{,}029{,}388 \) 的分拆数表，这些结果被哈代（Hardy）和拉马努金（Ramanujan）1918年的论文所超越。<sup>[9](https://pyrkov-professor.ru/Portals/0/Mediateka/MO/katz_v_j_editor_using_history_to_teach_mathematics_an_intern.pdf)</sup>

## 计算复杂性

计数问题出现在统计估计、统计物理、网络设计和经济学中，常与概率估计相关，而枚举组合学寻求它们的封闭形式表达式。这样的表达式并不总是存在：1847年基尔霍夫（Kirchhoff）证明了网络电阻可以通过计数其生成树来确定，并给出了一个涉及简单行列式计算的公式，但对于许多其他自然的计数问题，高效可计算的表达式不太可能存在。<sup>[4](https://www.cambridge.org/core/books/abs/computational-complexity/complexity-of-counting/8C2E96892F02F64673C12931FCB900CC)</sup>

复杂度类 \( \#\mathrm{P} \)（读作“sharp P”）由瓦利安特于1979年定义，由计算非确定性图灵机接受路径数的函数组成，而 \( \#\mathrm{P} \)-完全性——为刻画计算积和式的复杂性而引入——刻画了计数问题的难度。<sup>[3](https://www.researchgate.net/publication/2591186_Counting_Complexity)</sup><sup> • </sup><sup>[10](https://www.sciencedirect.com/science/article/pii/S0890540120301152)</sup> 一个典型现象是，一个计数问题可能很难，而相应的判定问题却很简单：判定一个二部图是否包含完美匹配是容易的，而计数这样的匹配数则是 \( \#\mathrm{P} \)-完全的。<sup>[4](https://www.cambridge.org/core/books/abs/computational-complexity/complexity-of-counting/8C2E96892F02F64673C12931FCB900CC)</sup><sup> • </sup><sup>[11](https://people.csail.mit.edu/virgi/6.s078/papers/approxcountwitness.pdf)</sup>

**近似计数。** 当精确计数很难时，近似可能更容易也可能更难；困难的计数问题有时可以用随机方法近似，而另一些则难以获得好的近似。<sup>[12](https://renyi.hu/~miklosi/CCC/ComputationalComplexityOfCountingAndSampling.pdf)</sup> 对于没有显式大小公式的大型有限集，随机算法可以通过在该集合及其递归定义的子集上模拟马尔可夫链来近似计数。<sup>[13](https://www.nationalacademies.org/read/2026/chapter/4)</sup> 函数 \( f \) 的随机近似方案接受一个实例 \( x \) 和一个误差容限 \( \varepsilon > 0 \)，输出 \( z \) 使得 \( \Pr\left[ e^{-\varepsilon} f(x) \le z \le e^{\varepsilon} f(x) \right] \ge 3/4 \)；若其运行时间关于 \( |x| \) 和 \( \varepsilon^{-1} \) 是多项式的，则称为完全多项式随机近似方案（FPRAS）。<sup>[14](https://www.cs.ox.ac.uk/people/leslieann.goldberg/papers/ising.pdf)</sup>

## 应用

组合学，特别是整数分拆和平面分拆，用于统计力学中晶格结构的计数及其他问题，其中伊辛模型是主要例子；反过来，统计力学也被应用于组合学。<sup>[6](https://dlmf.nist.gov/26.20)</sup> 物理组合学将计数问题——如确定配分函数系数或枚举离散构型——转化为系综和自由能的语言，应用涵盖经典和量子自旋系统、网络推断、软物质中的自组装以及量子电路模拟。<sup>[15](https://www.nature.com/nature-index/topics/l3/statistical-mechanics-physical-combinatorics-and-mathematical-aspects-of-condensed-matter)</sup> 组合学文献中还收录了在工程学、晶体学、生物学和计算机科学中的进一步应用，波利亚（Pólya）1937年关于组合学在化学中应用的著作以波利亚与里德（1987）的名义出版了英文版。<sup>[6](https://dlmf.nist.gov/26.20)</sup> 枚举组合学本身关注组合对象的精确计数和渐近计数，与概率论、几何学、代数学、统计物理、计算机科学和生物学有着紧密联系。<sup>[16](https://ems.press/journals/owr/articles/14299904)</sup>

## References

1. [CS 103X Course Notes, Chapter 9: Counting, Stanford University](https://web.stanford.edu/class/cs103x/cs103x-notes.pdf)
2. [Alexander Hulpke, Combinatorics course notes, MATH 501/2, Colorado State University](https://www.math.colostate.edu/~hulpke/lectures/m501/notes.html)
3. [Counting Complexity (Valiant's #P), ResearchGate](https://www.researchgate.net/publication/2591186_Counting_Complexity)
4. [Complexity of counting, Chapter 17, Computational Complexity: A Modern Approach, Cambridge University Press](https://www.cambridge.org/core/books/abs/computational-complexity/complexity-of-counting/8C2E96892F02F64673C12931FCB900CC)
5. [Counting on the Past: The Birth of Combinatorics in Classical India, SIAM](https://epubs.siam.org/doi/full/10.1137/25M180634X)
6. [DLMF §26.20 Physical Applications, NIST Digital Library of Mathematical Functions](https://dlmf.nist.gov/26.20)
7. [Historical Development of Combinatorics, BookofProofs](https://bookofproofs.github.io/branches/combinatorics/historical-development-of-combinatorics.html)
8. [The origins of modern combinatorics, Combinatorics: Ancient and Modern, Oxford Academic](https://academic.oup.com/book/11334/chapter-abstract/159960872)
9. [Combinatorics: a Historical and Pedagogical Approach, in Using History to Teach Mathematics, MAA](https://pyrkov-professor.ru/Portals/0/Mediateka/MO/katz_v_j_editor_using_history_to_teach_mathematics_an_intern.pdf)
10. [A structured view on weighted counting with relations to counting, quantum computation and applications, Information and Computation](https://www.sciencedirect.com/science/article/pii/S0890540120301152)
11. [Approximately counting and sampling small witnesses using a colourful decision oracle](https://people.csail.mit.edu/virgi/6.s078/papers/approxcountwitness.pdf)
12. [Computational complexity of counting and sampling, lecture notes](https://renyi.hu/~miklosi/CCC/ComputationalComplexityOfCountingAndSampling.pdf)
13. [Approximate Counting Via Markov Chains, in Probability and Algorithms, National Academies Press](https://www.nationalacademies.org/read/2026/chapter/4)
14. [The complexity of approximate counting, Leslie Ann Goldberg, University of Oxford](https://www.cs.ox.ac.uk/people/leslieann.goldberg/papers/ising.pdf)
15. [Statistical Mechanics, Physical Combinatorics and Mathematical Aspects of Condensed Matter, Nature Index](https://www.nature.com/nature-index/topics/l3/statistical-mechanics-physical-combinatorics-and-mathematical-aspects-of-condensed-matter)
16. [Enumerative Combinatorics, EMS Press](https://ems.press/journals/owr/articles/14299904)

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

Topic: 物质世界与数学 › 数学与统计学 › 逻辑与离散数学 › General discrete mathematics and discrete structures › Combinatorics › Enumerative combinatorics › Enumerative combinatorics overview and specific enumeration problems

Copyright 2026 Edgepedia

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

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

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