Distribute n identical objects into r distinct groups

This is called stars and bars method. suppose the stars are objects and space between bars represents objects corresponding to a certain group. Here is a visual representation:

$\underbrace{*****}_{\text{first group}}|\underbrace{******}_{\text{second group}}|\underbrace{*****}_\text{third group}|\underbrace{**}_\text{fourth group}$

Check each arrangement of bars provides a unique group separation and each group separation corresponds to a unique bar arrangement.Also check to seperate the stars in n groups only (n-1) bars are required.

then all you need to do is see how many bar arrangements are possible. Observe that when you have the $n-1$ bars and $k$ stars (assuming there are k objects to sort into n groups) then there are $n-1+k$ positions the stars and bars can take. So there are $\binom{n+k-1}{n-1}$ ways to chose the positions of the bars.


The problem gets harder when the boxes are identical, because for example: he following arrangements are the same: $*|***|**$ and $**|*|***$ In the problem where the boxes are different the answer would somehow correspond to distributing coins between people. When the boxes are identical however it corresponds to finding the number of partitions of the number into x or less non-zero parts. So if we define $p_k(n)$ to be the number of partitions of n numbers into exactly $k$ non-zero pieces then we get the number of ways to put n identical marbles into k identical boxes is $\sum_{k=0}^np_k$. However there is no pretty formula to calculate $p_k$ or $\sum_{k=0}^np_k$.