What the stars and bars method does

A stars-and-bars problem treats each identical item as a star and each divider between containers as a bar. The count becomes a combinations problem over the positions in one line.

The standard formula

If nn identical items go into kk distinct containers, the total number of distributions is inom{n+k-1}{n}.

Common uses

This appears in distributing candies, allocating resources, and counting non-negative integer solutions to equations like x1+x2+cdots+xk=nx_1 + x_2 + cdots + x_k = n.