Combinations with
repetition.
Count the selections you can make when the same kind may be picked more than once.
- Every kind at least once
- 0
- No repeats, C(n, r)
- 4
- Order matters too
- 64
Only how many of each kind counts, not the order, so 20 selections cover everything from all 3 of one kind to the most mixed spread.
One selection as stars and bars
Selection 1 of 20, AAA: A 3, B 0, C 0, D 0. Each dot is an item and each bar starts the next kind.
Selections by kinds used
Of the 20 selections, 4 use 1 kind, 12 use 2 kinds, 4 use 3 kinds.
All 20 selections, kinds named A, B, C
| # | Selection | How many of each |
|---|---|---|
| 1 | AAA | A 3, B 0, C 0, D 0 |
| 2 | AAB | A 2, B 1, C 0, D 0 |
| 3 | AAC | A 2, B 0, C 1, D 0 |
| 4 | AAD | A 2, B 0, C 0, D 1 |
| 5 | ABB | A 1, B 2, C 0, D 0 |
| 6 | ABC | A 1, B 1, C 1, D 0 |
| 7 | ABD | A 1, B 1, C 0, D 1 |
| 8 | ACC | A 1, B 0, C 2, D 0 |
How many kinds each selection uses
| Kinds used | Selections | Share |
|---|---|---|
| 1 | 4 | 20% |
| 2 | 12 | 60% |
| 3 | 4 | 20% |
Working
- 1Stars and bars: a dot per item, a bar between kinds3 stars + 3 bars = 6 symbols
- 2Choose which places hold the 3 starsC(6, 3) =6 × 5 × 43 × 2 × 1
- 3Multiply out and divide=1206= 20
- 4Check: choosing the bar places instead gives the same countC(6, 3) = 20
- 5Check: selections by number of kinds used add back up4 + 12 + 4 = 20
How it's worked out
You choose r items from n kinds. Any kind may be picked again, and the order of the picks does not matter. Three scoops of vanilla, vanilla and mint is one selection however the scoops are stacked. A selection like this is called a multiset, a set in which items may repeat.
The reason is a drawing called stars and bars. Write each chosen item as a star and put a bar between one kind and the next, so n kinds need n − 1 bars. For 3 scoops from 4 flavors, that is 3 stars and 3 bars, 6 symbols in a row. Every row of stars and bars is one selection, and every selection gives one row. So you only need to count the ways to pick which of the 6 places hold stars.
Levin's open textbook works the same idea with 7 cookies for 4 kids: 7 stars and 3 bars, 120 ways. Joy Morris states the general rule as n + r − 1 choose r. Choosing the bar places instead of the star places gives the same number, which is one of the checks in the steps.
That second count is for a minimum. If every kind must appear at least m times, set m of each kind aside first, then choose the rest freely. For 13 items from 5 kinds with at least 2 of each, 10 go aside and 3 are left, which gives 35 selections.
Worked examples
Lucia picks three scoops from four flavors
The shop has 4 flavors and Lucia wants 3 scoops in a cup. She may have two of the same flavor, or all three. With repeats allowed there are 20 different cups.
If every scoop had to be a different flavor, she would have only C(4, 3) = 4 cups. All of the other 16 cups repeat a flavor at least once.
Theo lists the face sets five dice can show
Ignore which die shows which face, and five dice are 5 picks from 6 faces with repeats. There are 252 face sets, against 6 to the power 5 = 7,776 ordered rolls.
The face sets are not equally likely. 6 sets use one face only, like five sixes, and each comes up in just one ordered roll. 6 sets use five different faces, like 1, 2, 3, 4, 5, and each of those comes up in 120 ordered rolls.
Seven cookies for four kids, at least one each
With no rule, the 7 cookies can be shared among 4 kids in 120 ways, because some kids may get none. The parent wants every kid to get at least one.
So hand out 4 cookies first, one per kid. That leaves 3 cookies to share freely, which can be done in 20 ways. At least two each would need 8 cookies, so with 7 the count is 0.
Reading your result
r can be larger than n. Kinds repeat, so you can choose more items than there are kinds. Five marbles from 2 colors give 6 selections, from five of one color to five of the other.
It also counts whole-number solutions. x1 + x2 + x3 = 11 with each x at least 0 is 11 items from 3 kinds, where each x says how many of that kind you take. That gives 78 solutions, and at least 1 each gives 45.
The split by kinds used shows the shape. A selection uses some number of different kinds, from 1 up to the smaller of n and r. Those groups add back up to the count, which is a quick check on any answer you work out by hand.
Large counts stay exact. A dozen donuts from 5 kinds is 1,820, which is small. With 100 kinds and 100 items the count has 59 digits, and every one of them is shown.
Common mistakes
- Using C(n, r) when repeats are allowed. That count assumes each kind is used at most once, so it is too small for scoops, dice or coins.
- Treating each selection as equally likely. With random draws, a selection with many repeats is usually less likely than one with all different kinds, so 1 over the count is not its chance.
- Counting distinct items this way. Stars and bars needs identical items. Seven different books into 4 boxes is 4 to the power 7 ways, not this count.
- Forgetting a cap. "At most two of each flavor" is a different problem. It needs inclusion and exclusion on top of this count.