Ekuation

operation

Stars and Bars Calculator -- Combinations with Repetition

Calculate C(n+r-1, r) -- the number of ways to choose r items from n types when repetition is allowed.

Back to Combinatorics Calculator

Die Gesamtzahl der verschiedenen Elemente in der Menge

Die Anzahl der aus der Gesamtmenge gewählten oder angeordneten Elemente

Formel
Crep(n,r)=(n+r1r)C_{rep}(n,\,r) = \dbinom{n+r-1}{r}

Beispiel ausprobieren

Wähle ein Szenario, um zu sehen, wie der Rechner funktioniert, und passe dann die Werte an

3 Ice Cream Scoops from 5 Flavours

Choose 3 scoops from 5 flavours with repetition — how many distinct combinations?

Wichtige Werte: n = 5 flavours · r = 3 scoops · C(7,3) = 35

Distributing $10 Among 4 Projects

How many ways can a budget of 10 identical $1 units be allocated to 4 projects (each can receive 0 or more)?

Wichtige Werte: n = 4 projects · r = 10 units · C(13,10) = 286

Dokumentation

The Stars and Bars Technique

Stars and bars counts the ways to distribute nn identical objects into kk distinct bins. Visualize the objects as stars and the dividers between bins as bars (|):

★★★|★|★★ → bins get 3, 1, 2 objects
★|★★★★|★ → bins get 1, 4, 1 objects
||★★★★★★ → bins get 0, 0, 6 objects

With nn stars and k1k - 1 bars, we arrange n+k1n + k - 1 symbols in a row, choosing positions for the bars:

(n+k1k1)=(n+k1n)\binom{n + k - 1}{k - 1} = \binom{n + k - 1}{n}

Examples

Problemn (stars)k (bins)Ways
10 candies among 3 children103(122)=66\binom{12}{2} = 66
Sum of 4 non-neg integers = 774(103)=120\binom{10}{3} = 120
$20 invested in 5 stocks ($1 units)205(244)=10,626\binom{24}{4} = 10{,}626

At Least One per Bin

If every bin must receive at least one object, pre-place one object in each bin, then distribute the remaining nkn - k:

(n1k1)\binom{n - 1}{k - 1}

This is the number of compositions of nn into kk positive parts.

Example: Distribute 10 candies among 3 children so each gets at least one: (92)=36\binom{9}{2} = 36 ways (vs. 66 ways if empty bins are allowed).


Connection to Other Problems

Stars and bars is equivalent to several other combinatorial problems:

  • Non-negative integer solutions: How many solutions does x1+x2++xk=nx_1 + x_2 + \cdots + x_k = n have with xi0x_i \geq 0?
  • Multiset selection: Choosing nn items from kk types with repetition allowed (same as combinations with repetition).
  • Weak compositions: Ordered sequences of non-negative integers summing to nn.

Frequently Asked Questions

What is the stars and bars technique?

Stars and bars is a combinatorial method for counting the ways to distribute nn identical objects into kk distinct bins. Objects are represented as stars and dividers between bins as bars. The formula is C(n+k1,k1)C(n + k - 1, k - 1).

How do you use stars and bars with a minimum constraint?

If every bin must receive at least one object, pre-place one object in each bin, then distribute the remaining nkn - k objects freely. The formula becomes C(n1,k1)C(n - 1, k - 1). For example, distributing 10 candies among 3 children (each gets at least one) gives C(9,2)=36C(9, 2) = 36 ways.

What problems can stars and bars solve?

Stars and bars solves three equivalent problems: distributing identical objects into distinct bins, counting non-negative integer solutions to x1+x2++xk=nx_1 + x_2 + \ldots + x_k = n, and selecting nn items from kk types with repetition allowed (multiset selection).

How is stars and bars related to combinations with repetition?

Stars and bars is exactly the formula for combinations with repetition. Choosing nn items from kk types (repeats allowed) equals C(n+k1,n)C(n + k - 1, n). Both problems reduce to arranging nn stars and k1k - 1 bars in a row.

Can stars and bars handle upper bound constraints?

Not directly. For constraints like “no bin gets more than mm objects,” use inclusion-exclusion on top of the basic stars and bars formula. Subtract cases where one or more bins exceed the limit, add back over-counted cases, and so on.

Related operation Variants

Explore more operation options

More Math Calculators

Explore the category

Rechnersuche

Rechner suchen und finden