At a party $n$ people toss their hats into a pile in a closet.$\dots$ [duplicate]
Solution 1:
The number of combinations for exactly $k$ out of $n$ people to select the correct hat is:
$ C_{n,k}= \begin{cases} \displaystyle[\frac{n!}{e}] & \text{$k=0$}\\ \displaystyle\binom{n}{k}\cdot{C_{n-k,0}} & \text{$k>0$}\\ \end{cases} $
So the probability that exactly $k$ out of $n$ people will select the correct hat is:
$\displaystyle{P_{n,k}=\frac{C_{n,k}}{n!}}$
Hence the expected number of people to select the correct hat is:
$\displaystyle\sum\limits_{k=1}^{n}k\cdot{P_{n,k}}$