# UVa 10648

## Summary

Given ${\displaystyle m}$ distinguishable boxes and ${\displaystyle n}$ chocolates to put in those boxes with equal probability, what is the probability that at least one box is empty? This set of numbers can be calculated exactly by the Stirling Number of the Second Kind.

## Explanation

The Stirling Number of the Second Kind (using Knuth's notation ${\displaystyle \{_{m}^{n}\}}$) counts the number of ways to partition a set of ${\displaystyle n}$ elements into ${\displaystyle m}$ non-empty sets. How does this solve our problem?

For a given ${\displaystyle n}$, each of the ${\displaystyle n^{m}}$ occur with equal probability. ${\displaystyle \{_{m}^{n}\}}$ calculates the number of sets, so the boxes would not be distinctive. e.g.: ${\displaystyle \{_{2}^{3}\}}$ = ${\displaystyle \{\{1,2\},\{3\}\},\{\{1\},\{2,3\}\},\{\{1,3\},\{2\}\}}$, but since the boxes are distinctive, we would have have to multiply it by ${\displaystyle 2!=2}$ to get all the ordering.

Now there are two (equivalent) ways to go about:

The first is calculating ${\displaystyle \{_{m}^{n}\}}$ - the number of ways to put ${\displaystyle n}$ distinctive chocolates into ${\displaystyle m}$ boxes - or having no empty boxes. Since the boxes are distinct, multiply it by ${\displaystyle m!}$ to get the total number of ways we can have no empty boxes. The distribution is equal, and every way happens with an equal probability, thus we can divide it by the total number of ways (which is simply ${\displaystyle m^{n}}$) to get the probability of having no empty boxes. To get the inverse of this, we subtract that probability from 1. (The sets are totally disjoint, afterall.)

The second is calculating ${\displaystyle \Sigma _{i=1}^{m-1}\{_{i}^{n}\}}$ - the number of ways to put ${\displaystyle n}$ distinctive chocolates into ${\displaystyle 1,2,\ldots ,m-1}$ boxes. This will count the number of ways there will be ${\displaystyle m-1,m-2,\ldots ,1}$ empty boxes, respectively. For each way, we have to account for the fact that all the boxes are distinctive, so we multiply it by ${\displaystyle m!}$, but to factor out the double counting we put on all the empty boxes (since it doesn't matter), we have to divide it by ${\displaystyle (m-i)!}$ - the number of empty boxes. This means we are actually calculate ${\displaystyle m!\Sigma _{i=1}^{m-1}(m-i)!\{_{i}^{n}\}}$. As with the first method, we can then divide it by the total number of ways (which is simply ${\displaystyle m^{n}}$) to get the probability.

```50 12
50 12
100 3
100 12
32 7
-1
```

## Output

```Case 1: 0.1476651
Case 2: 0.1476651
Case 3: 0.0000000
Case 4: 0.0019960
Case 5: 0.0500009
```