# 星条法（组合数学）

**星条法**是组合数学中的一种计数技巧，用于确定将 n 个不可区分的物体放入 k 个可区分盒子中的方法数，等价于方程 \( x_1 + x_2 + \cdots + x_k = n \) 的非负整数解个数。答案为二项式系数 \( \binom{n+k-1}{k-1} = \binom{n+k-1}{n} \)。该方法将每一种分配编码为一行 n 颗星（代表物体），由 k − 1 条竖线（代表盒子之间的隔板）分隔，然后计算这些符号的排列方式数。<sup>[1](https://brilliant.org/wiki/integer-equations-star-and-bars/)</sup>

| 关键事实 | 详情 |
|---|---|
| 核心计数 | 将 n 个不可区分的球放入 k 个有标号盒子的方法数为 \( \binom{n+k-1}{n} = \binom{n+k-1}{k-1} \)<sup>[1](https://brilliant.org/wiki/integer-equations-star-and-bars/)</sup> |
| 编码方式 | 写 \( x_1 \) 颗星、一条竖线、\( x_2 \) 颗星、一条竖线，依此类推直到 \( x_k \) 颗星：共 n 颗星和 k − 1 条竖线，总计 \( n+k-1 \) 个符号<sup>[2](https://www.learnmathclass.com/combinatorics/visual-tools/weak-composition)</sup> |
| 弱组合 | 计数等于 n 拆分为 k 个部分的弱组合数，即和为 n 的非负整数序列的个数<sup>[3](https://people.csail.mit.edu/rmwu/static/files/notes/18-211-notes.pdf)</sup> |
| 正整数解 | 方程 \( \sum_{i=1}^{k} x_i = n \) 有 \( \binom{n-1}{k-1} \) 个正整数解<sup>[4](https://notes.imt-decal.org/counting/stars-and-bars.html)</sup> |
| 全部组合 | 对所有部分数求和，n 的组合总数为 \( 2^{n-1} \)<sup>[5](https://sites.math.northwestern.edu/~scanez/courses/notes/lecture-notes-306.pdf)</sup> |
| 多重集 | 同一公式可计数允许重复的无序选取：从 t 种可用类型中选取 r 个物体，有 \( \binom{r+t-1}{r} \) 种可能<sup>[6](https://guraltsev.github.io/combinatorics-fall2026/lecture-notes/unit-1-enumeration/03-applications-of-combinations-and-repetition.html)</sup> |

## 双射

经典论证将每个解映射为一个符号串。为编码解 \( (x_1, \ldots, x_k) \)，写 \( x_1 \) 颗星，然后一条竖线，然后 \( x_2 \) 颗星，然后一条竖线，依此类推，最后以 \( x_k \) 颗星结尾。这一行包含 n 颗星和 k − 1 条竖线，因此总共有 \( n+k-1 \) 个符号。<sup>[2](https://www.learnmathclass.com/combinatorics/visual-tools/weak-composition)</sup>

每个弱组合由竖线的位置决定。竖线将这一行分成 k 组，第 i 组包含 \( x_i \) 颗星。不同的竖线位置给出不同的组合，而每个组合都来自唯一的竖线位置；相邻的竖线编码 \( x_i = 0 \)，位于开头或结尾的竖线分别编码第一个或最后一个位置为零。<sup>[2](https://www.learnmathclass.com/combinatorics/visual-tools/weak-composition)</sup><sup> • </sup><sup>[6](https://guraltsev.github.io/combinatorics-fall2026/lecture-notes/unit-1-enumeration/03-applications-of-combinations-and-repetition.html)</sup> 计数这些位置是一个普通的选取问题：从 \( n+k-1 \) 个槽位中选出 k − 1 个竖线位置，得到 \( \binom{n+k-1}{k-1} \)。<sup>[5](https://sites.math.northwestern.edu/~scanez/courses/notes/lecture-notes-306.pdf)</sup>

一个实例展示了具体操作。对于 \( a + b + c + d = 12 \)，配置 \( *\,|\,*****\,|\,****\,|\,** \) 编码了解 \( 1 + 5 + 4 + 2 = 12 \)，而 \( |\,*****\,|\,***\,|\,**** \) 编码了 \( 0 + 5 + 3 + 4 = 12 \)。12 颗星和 3 条竖线占据 15 个位置，解的数量为 \( \binom{15}{3} = 455 \)。<sup>[1](https://brilliant.org/wiki/integer-equations-star-and-bars/)</sup>

两种二项式形式是同一个计数的两个解读方向：\( \binom{n+k-1}{k-1} \) 选取竖线位置，而 \( \binom{n+k-1}{n} \) 选取 n 颗星的位置，且 \( \binom{a}{b} = \binom{a}{a-b} \)。<sup>[2](https://www.learnmathclass.com/combinatorics/visual-tools/weak-composition)</sup>

## 该方法计数的对象

**弱组合与强组合。** n 的弱组合是一个和为 n 的非负整数序列 \( (a_1, \ldots, a_k) \)；若每个部分都为正，则称为组合。<sup>[3](https://people.csail.mit.edu/rmwu/static/files/notes/18-211-notes.pdf)</sup> 竖线位置不受限制的星条法计数的是弱组合。对于所有部分均为正的组合，竖线不能相邻，也不能位于两端。标准的修正方法是平移：先给每个部分一个单位，剩下 \( n-k \) 个单位自由分配，因此 n 拆分为 k 个部分的组合数为 \( \binom{n-1}{k-1} \)。<sup>[3](https://people.csail.mit.edu/rmwu/static/files/notes/18-211-notes.pdf)</sup><sup> • </sup><sup>[4](https://notes.imt-decal.org/counting/stars-and-bars.html)</sup> 另一种理解方式：将 k 拆分为 \( \ell \) 个部分的组合 \( (b_1, \ldots, b_{\ell}) \) 的每一项减去 1，得到 \( (b_1 - 1, \ldots, b_{\ell} - 1) \)，即 \( k-\ell \) 拆分为 \( \ell \) 个部分的弱组合，且该映射是双射。<sup>[7](https://www.cip.ifi.lmu.de/~grinberg/t/17f/60610lectures2017-Galvin.pdf)</sup>

对所有部分数 k 求和 \( \binom{n-1}{k-1} \) 得到 n 的组合总数，其值为 \( 2^{n-1} \)。直接的星条法解读给出相同的数：n 颗星之间有 \( n-1 \) 个间隙，每个间隙独立地放置或不放置一条竖线，因此有 \( 2^{n-1} \) 种选择。<sup>[3](https://people.csail.mit.edu/rmwu/static/files/notes/18-211-notes.pdf)</sup><sup> • </sup><sup>[5](https://sites.math.northwestern.edu/~scanez/courses/notes/lecture-notes-306.pdf)</sup>

**多重集与重复选取。** 允许重复的无序选取称为多重集，由记录每种类型被选取次数的重数向量来表示。各分量之和必须等于选取规模，因此问题转化为计数非负整数解，星条法适用。例如，从十种类型中购买六个甜甜圈，使用六颗星和九条竖线。<sup>[6](https://guraltsev.github.io/combinatorics-fall2026/lecture-notes/unit-1-enumeration/03-applications-of-combinations-and-repetition.html)</sup> 在基本选取的四模型表（有序或无序、允许或不允许重复）中，星条法提供了剩余那一行的计数，即允许重复的无序选取。<sup>[6](https://guraltsev.github.io/combinatorics-fall2026/lecture-notes/unit-1-enumeration/03-applications-of-combinations-and-repetition.html)</sup>

**该方法不计数什么。** 该方法将被分配的物体视为不可区分。它计数从 5 种口味中购买 8 个甜甜圈的方式，其中只关心每种口味的数量，但它不能直接计数将 8 本不同的书分配给 5 名学生的方式，因为那里的物体是可区分的。<sup>[8](https://livephysics.com/cheat-sheets/math-stars-and-bars-counting-reference/)</sup>

## 对部分的约束

**下界。** 要求 \( x_i \ge L_i \) 可通过替换 \( y_i = x_i - L_i \) 来处理，将有约束的问题转化为总量减少的无约束非负问题。<sup>[9](https://neelmishra.github.io/blog/math/probability-statistics/combinatorial-analysis/stars-and-bars.html)</sup> 正整数解公式是 \( L_i = 1 \) 的特例：将 20 张一美元钞票分给 3 位朋友使每人至少得到一张，有 \( \binom{19}{2} \) 个解。<sup>[4](https://notes.imt-decal.org/counting/stars-and-bars.html)</sup>

**上界。** 诸如 \( x_i \le b \) 的上限无法从单个二项式系数直接读出。

**生成函数概述。** 星条法的计数也可以从生成函数恒等式中导出。所有组合的生成函数为 \( C(z) = 1/(1 - 2z) \)，其系数给出 \( 2^{n-1} \)，这一结果通常在本科课程中直接用星条法证明。<sup>[10](https://jaypantone.com/courses/winter16math118/lecture-notes/lecture-notes-05.pdf)</sup> 符号方法将同一框架推广到受限类别，例如每部分大小至多为 r 的组合，而不会增加额外的困难。<sup>[10](https://jaypantone.com/courses/winter16math118/lecture-notes/lecture-notes-05.pdf)</sup>

## 相关结构

星条法位于一个更广泛的等价编码网络之中。四种模型中的每一种都可以用下一种的语言重新表述：格路径作为步骤串，变位词作为符号出现次数固定的串，多重集作为重数向量，重数向量作为星条串，因此它们共享同一个底层计数问题。<sup>[6](https://guraltsev.github.io/combinatorics-fall2026/lecture-notes/unit-1-enumeration/03-applications-of-combinations-and-repetition.html)</sup> 弱组合本身是对称函数理论中的基本索引对象，出现在简单分配问题之外的计数组合学和代数组合学中。同一论证还证明了二项式恒等式：将 a 颗星和 b − 1 条竖线排成一行，既给出 \( \binom{b}{a} \) 又给出 \( \binom{b+a-1}{b-1} \) 作为同一事物的计数，从而建立它们的相等关系。<sup>[11](https://vadim.sdsu.edu/teaching/579/s26/coursepack.pdf)</sup>

## References

1. [Integer Equations - Stars and Bars, Brilliant Math & Science Wiki](https://brilliant.org/wiki/integer-equations-star-and-bars/)
2. [Weak Composition: Stars and Bars Formula, Learn Math Class](https://www.learnmathclass.com/combinatorics/visual-tools/weak-composition)
3. [Rachel Wu, MIT 18.211 lecture notes (September 13, 2018)](https://people.csail.mit.edu/rmwu/static/files/notes/18-211-notes.pdf)
4. [Stars and Bars, notes.imt-decal.org](https://notes.imt-decal.org/counting/stars-and-bars.html)
5. [Math 306: Combinatorics & Discrete Mathematics lecture notes, Northwestern University](https://sites.math.northwestern.edu/~scanez/courses/notes/lecture-notes-306.pdf)
6. [Applications of combinations and combinations with repetition, Combinatorics lecture notes, Fall 2026](https://guraltsev.github.io/combinatorics-fall2026/lecture-notes/unit-1-enumeration/03-applications-of-combinations-and-repetition.html)
7. [Basic Discrete Mathematics 31, lecture notes by D. Galvin, LMU Munich](https://www.cip.ifi.lmu.de/~grinberg/t/17f/60610lectures2017-Galvin.pdf)
8. [Stars and Bars Counting Reference Cheat Sheet, LivePhysics](https://livephysics.com/cheat-sheets/math-stars-and-bars-counting-reference/)
9. [Integer Solutions & Stars and Bars, Neel Mishra](https://neelmishra.github.io/blog/math/probability-statistics/combinatorial-analysis/stars-and-bars.html)
10. [Jay Pantone, Lecture 5: Compositions, Words, Trees, and More](https://jaypantone.com/courses/winter16math118/lecture-notes/lecture-notes-05.pdf)
11. [Math 579: Combinatorics coursepack, San Diego State University](https://vadim.sdsu.edu/teaching/579/s26/coursepack.pdf)

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

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

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/stars-and-bars-combinatorics

English original: https://www.edgepedia.org/stars-and-bars-combinatorics
