DigitHelm

Combinations with Repetition | Stars & Bars

Calculate multiset combinations C̄(n,r) = C(n+r−1,r) where repetition is allowed. Features stars & bars visualization, step-by-step working, multiset listing, all four combinatorial variants, BigInt exact arithmetic, and session persistence.

Presets

Number of different item types

Can exceed n, repeats allowed

Enter to calculate  ·  Esc to reset

What Is the Combinations with Repetition | Stars & Bars?

Combinations with repetition, also called multiset coefficients or the stars and bars formula, count the number of ways to select r items from n distinct types when you can pick the same type more than once and the order of selection does not matter. The key insight is that this is equivalent to a completely different problem: arranging r identical stars and (n−1) identical bars in a row of n+r−1 positions.

  • All four combinatorial variants in one view, C̄(n,r) with repetition, C(n,r) without, P(n,r) permutations, and nʳ, so you can compare directly.
  • Stars & Bars visualization, sample arrangements show exactly how stars ★ and bars | correspond to real selections, making the abstract formula tangible.
  • r can exceed n, unlike standard combinations, you can choose more items than there are types (e.g., 5 scoops from 3 flavors, all 5 could be the same flavor).
  • Multiset listing, for small inputs, every multiset is enumerated and shown labelled A, B, C, … so you can verify the count by inspection.
  • BigInt exact arithmetic, uses the efficient multiplicative formula, not full factorial computation, for accurate results at any scale.
  • Step-by-step simplification, see how the (n−1)! factor cancels from the numerator, leaving just r terms to multiply and divide.

Formula

Combinations with Repetition (Multiset Coefficient)

C̄(n, r) = C(n + r − 1, r)

= (n + r − 1)! / (r! × (n − 1)!)

= [n(n+1)(n+2)…(n+r−1)] / r!

Stars & Bars Interpretation

Arrange r stars ★ and (n−1) bars | in (n+r−1) positions

Choose r positions for the stars → C(n+r−1, r) ways

Comparison with Standard Combinations

Without repetition: C(n, r) = n! / (r! × (n−r)!) ← requires r ≤ n

With repetition: C̄(n, r) = C(n+r−1, r) ← r can exceed n

Distributing Objects into Bins (equivalent problem)

C̄(n, r) = ways to place r identical items into n distinct bins

= C(n+r−1, n−1) ← same value by symmetry

SymbolNameDescription
nTypes / binsNumber of distinct item types or container bins, must be ≥ 1
rItems chosenNumber of items selected, can exceed n when repeats are allowed
C̄(n,r)Multiset coefficientThe count of size-r multisets drawn from an n-element set
n+r−1Adjusted sizeThe effective pool size after accounting for repetition
r!r factorialDivides out orderings since combination order doesn't matter
n−1Number of barsIn stars & bars: n bins require n−1 dividers

Key Identities & Special Cases

C̄(n, 0) = 1 (one way to choose nothing, the empty multiset)

C̄(n, 1) = n (choose one item: n choices, same as without repetition)

C̄(1, r) = 1 (only one type → only one selection regardless of r)

C̄(2, r) = r + 1 (two types → r+1 choices: 0,1,2,…,r of type A)

C̄(n, r) = C̄(n, r) by symmetry: C(n+r−1, r) = C(n+r−1, n−1)

How to Use

  1. 1
    Identify n and r: n = the number of distinct item types (flavors, colors, categories). r = how many items you are choosing. Remember: r is allowed to be larger than n.
  2. 2
    Enter values and calculate: Type n and r, then press Calculate or hit Enter. All four combinatorial values appear immediately for direct comparison.
  3. 3
    Read the Stars & Bars visual: For small inputs (n ≤ 8, r ≤ 12), sample arrangements appear showing how stars (items) and bars (dividers) correspond to specific multiset distributions.
  4. 4
    Expand for details: Click "Show Step-by-Step" to trace through the formula derivation. For C̄(n,r) ≤ 200, click "List All Multisets" to enumerate every possible selection.
  5. 5
    Try presets: Use the preset buttons for classic real-world scenarios: ice cream scoops, dice outcomes, pizza toppings, coin distributions, and colored marble draws.

Example Calculation

Example 1, Ice Cream Scoops (n=4, r=3)

An ice cream shop has 4 flavors: Vanilla (V), Chocolate (C), Strawberry (S), and Mint (M). You order 3 scoops and can choose the same flavor more than once. How many distinct orders exist?

n = 4, r = 3

C̄(4, 3) = C(4+3−1, 3) = C(6, 3)

= 6! / (3! × 3!) = 720 / (6 × 6) = 20

Stars & Bars: arrange 3 ★ and 3 | in 6 positions. Example: ★★|★|| = (2 Vanilla, 1 Chocolate, 0 Strawberry, 0 Mint). Without repetition, C(4,3) = 4, the 16 extra choices all involve at least one repeated flavor.

Example 2, Distributing Coins into Bags (n=3, r=5)

Place 5 identical coins into 3 labeled bags (some bags may be empty). How many distributions exist?

n = 3 (bags), r = 5 (coins)

C̄(3, 5) = C(3+5−1, 5) = C(7, 5) = C(7, 2)

= (7 × 6) / (2 × 1) = 21

The 21 distributions include: (5,0,0), (4,1,0), (3,2,0), (3,1,1), (2,2,1), (0,0,5), … all the non-negative integer solutions to x₁ + x₂ + x₃ = 5.

Example 3, Dice (n=6, r=2): Rolling Two Dice

Roll two standard dice and record the pair of face values without caring about which die shows what. How many distinct outcome pairs are there?

n = 6 (faces: 1–6), r = 2 (dice)

C̄(6, 2) = C(6+2−1, 2) = C(7, 2) = (7 × 6) / 2 = 21

vs. ordered pairs (order matters): 6² = 36

vs. pairs without repetition (no doubles): C(6,2) = 15

The 21 includes 6 doubles (1,1), (2,2), …, (6,6) plus 15 mixed pairs like (1,2), (3,5), etc.

Example 4, Polynomial Monomials (n=3 variables, degree r=4)

How many distinct monomials of degree 4 exist in 3 variables (x, y, z)? (e.g., x⁴, x³y, x²yz, xyz², z⁴, …)

n = 3 (x, y, z), r = 4 (total degree)

C̄(3, 4) = C(3+4−1, 4) = C(6, 4) = C(6, 2) = 15

Monomials: x⁴, x³y, x³z, x²y², x²yz, x²z², xy³, xy²z, xyz², xz³, y⁴, y³z, y²z², yz³, z⁴

Understanding Combinations with Repetition | Stars & Bars

Most people encounter combinations through the standard formula C(n, r) = n!/(r!(n−r)!), where every item can be chosen at most once. But many real counting problems allow the same item to appear multiple times in a selection, the number of scoops at an ice cream parlor, the outcomes when rolling several dice, distributing identical objects into bins, or counting polynomial terms. These are all multiset problems, and they require the combinations-with-repetition formula.

The Stars and Bars Method, A Visual Proof

The formula C̄(n, r) = C(n+r−1, r) comes from a beautiful visual argument known as the Stars and Bars method, introduced by William Feller. Imagine you want to select r items from n types. Represent each chosen item as a star ★, and use n−1 vertical bars | to separate the n types. For example, with n=3 types and r=5 items:

★ ★ ★ | ★ | ★ → (3 of type A, 1 of type B, 1 of type C)

| ★ ★ | ★ ★ ★ → (0 of type A, 2 of type B, 3 of type C)

★ ★ ★ ★ ★ | | → (5 of type A, 0 of type B, 0 of type C)

Each unique selection corresponds to exactly one arrangement of r stars and n−1 bars in a row of n+r−1 positions. Choosing which r positions hold stars (the rest hold bars) gives us C(n+r−1, r) arrangements, the exact count of distinct multisets.

The Distributing Objects Problem

The formula C̄(n, r) also counts the number of non-negative integer solutions to: x₁ + x₂ + x₃ + … + xₙ = r, where each xᵢ represents how many of the r items go into bin i. This “distributing identical objects into distinct bins” framing appears in probability theory (occupancy problems), information theory (code words), and combinatorial optimization.

When to Use Which Formula

ScenarioOrder matters?Repeats OK?FormulaName
Committee selectionNoNoC(n,r)Combination
Ice cream scoopsNoYesC̄(n,r)Multiset / Stars & Bars
Ranking competitionYesNoP(n,r)Permutation
PIN code digitsYesYesPerm. with repetition

Real-World Applications

FieldApplication
Food & retailChoosing r items from n menu options when duplicates are allowed
Probability theoryOccupancy problems, distributing r balls into n labeled boxes
AlgebraCounting monomials of degree r in n variables (e.g. x²y, xy², x³)
Computer scienceCounting multisets in data structures, hash table analysis
Game designDice outcomes (unordered results from rolling r identical dice)
ChemistryCounting arrangements of atoms in molecules with repeated elements
StatisticsBootstrap sampling, resampling n observations r times with replacement
Network theoryCounting paths with repeated edge traversal in multigraphs

Generating Functions Connection

The generating function for C̄(n, r) is the coefficient of xʳ in the expansion of 1/(1−x)ⁿ = Σ C(n+r−1, r) xʳ. This connection to power series makes multiset coefficients central to analytic combinatorics and the study of integer partitions. When n=2, the formula gives C̄(2,r) = r+1, which matches the triangular arrangement in Pascal's triangle.

Comparison: With vs. Without Repetition

nrC(n,r), no repeatsC̄(n,r), repeats OKRatio C̄/C
32362.00×
434205.00×
5310353.50×
64151268.40×
10525220027.94×
661462462× (r=n: only 1 without repeats!)

Notice that when r = n, C(n,n) = 1, only one way to choose all items without repetition. But C̄(n,n) can be enormous because each item can be repeated any number of times.

Frequently Asked Questions

What is the difference between combinations with and without repetition?

The difference is whether you can pick the same item more than once.

  • Without repetition, each item selected at most once. Formula: C(n,r) = n! / (r!(n−r)!). Requires r ≤ n.
  • With repetition, the same item type can appear multiple times. Formula: C̄(n,r) = C(n+r−1, r). r can exceed n.

Example: choosing 2 scoops from 3 ice cream flavors:

  • Without repetition: C(3,2) = 3 options, must pick 2 different flavors
  • With repetition: C̄(3,2) = 6 options, can pick the same flavor twice (VV, CC, SS, VC, VS, CS)

Why is the formula C(n+r-1, r) and not just C(n, r)?

The Stars and Bars argument explains it. When repetition is allowed, you need to count arrangements of:

  • r stars ★ representing the items chosen
  • n−1 bars | acting as dividers between item types

These are arranged in a row of n+r−1 positions. Choosing which r positions hold stars (others hold bars) gives C(n+r−1, r) arrangements, each corresponding to exactly one multiset selection.

The n−1 effectively shifts the pool size to account for the extra "slots" created by allowing repetition.

Can r be larger than n in combinations with repetition?

Yes, this is one of the key differences from standard combinations.

Since you can pick the same type multiple times, r can be any non-negative integer regardless of n.

  • Example: n=2 (types: A and B), r=5: you can pick AAAAA, AAAAB, AAABB, AABBB, ABBBB, BBBBB, that's C̄(2,5) = 6 options
  • C(2,5) without repetition = 0 because you can't choose 5 from 2 without repeating

In standard C(n,r), having r > n gives zero. In C̄(n,r), r > n is perfectly valid.

What is the Stars and Bars method?

Stars and Bars is a visual proof technique for counting multiset combinations. It works by encoding each selection as an arrangement of two symbols:

  • ★ (star), represents one chosen item
  • | (bar), represents a divider between consecutive item types

For n types and r items, you have r stars and n−1 bars, in n+r−1 total positions. Each arrangement of these symbols corresponds to a unique selection.

n=3, r=4: ★★|★|★ means (2, 1, 1), 2 of type A, 1 of B, 1 of C

★★★★|| means (4, 0, 0), all 4 of type A

Counting arrangements = C(n+r−1, r) = the multiset coefficient.

How does this relate to distributing identical objects into distinct bins?

These are mathematically identical problems. "Distributing r identical objects into n labeled bins" is the same as "choosing r items from n types with repetition."

Both count the non-negative integer solutions to: x₁ + x₂ + … + xₙ = r

  • x₁ = number of items in bin 1 (or number of type-1 items chosen)
  • x₂ = number of items in bin 2 (or number of type-2 items chosen)
  • The total is always r

Answer: C̄(n, r) = C(n+r−1, r) for both framings.

How do I use this formula for probability problems?

When all multisets are equally likely, probability of a specific selection is:

P(specific multiset) = 1 / C̄(n, r)

Common applications:

  • Occupancy problems, probability that a specific bin gets at least k objects
  • Dice outcomes, probability of a specific unordered result from r dice
  • Sampling with replacement, if order is ignored, C̄(n,r) equally-likely outcomes

Note: if sampling is ordered (each sequence is equally likely, not each multiset), use nʳ as the total outcome count instead.

What is the connection to the binomial theorem and generating functions?

The multiset coefficient C̄(n, r) appears as the coefficient of xʳ in the power series expansion of 1/(1−x)ⁿ:

1/(1−x)ⁿ = Σ C(n+r−1, r) × xʳ for r = 0, 1, 2, …

This is the negative binomial series. It connects combinations with repetition to:

  • The binomial distribution with negative exponent
  • Generating functions for integer partition counting
  • Analytic combinatorics and formal power series

How is combinations with repetition used in computer science?

Several important algorithms and data structure analyses rely on this formula:

  • Multiset data structures, counting the number of possible multisets of size r from n element types
  • Hash table analysis, counting collisions when r keys hash into n buckets (occupancy model)
  • Combinatorial enumeration, generating all k-element multisets in lexicographic order
  • Dynamic programming, the Stars and Bars structure appears in subset-sum and knapsack variants
  • Algorithm complexity, analyzing worst-case inputs for algorithms that process multisets

The generating function connection also makes this formula central to formal language theory and automata analysis.

Related Calculators