An alternate solution to the hat-matching problem, probability of exactly $k$ matches the setup: $N$ people arrive at a party all of whom are wearing hats. We collect all the hats and then redistribute them. What is the probability that exactly $k$ of the party members receive their own hats back?
let $E_i$ denote the probability that the $i^{th}$ man receives his own hat back. Then, $\space\space E_{i_1}E_{i_2}\dots E_{i_n} \space\space$ is the event that men labelled $i_1 , i_2 , \dots i_n$ get their own hats back. which implies...
$P(E_{i_1}E_{i_2}\dots E_{i_n}) = \frac{(N-n)!}{N!}$ and $\color{red}{\sum\limits_{i_1<i_2<\cdots <i_n}}P(E_{i_1}E_{i_2}\cdots E_{i_n}) = \binom{N}{n}\frac{(N-n)!}{N!} = \frac{1}{n!}$
question1: are the above two formulas correct?
The probability that at least $k$ of the party members receive their own hats back (using the inclusion-exclusion principle) is  $$\sum_{i_1 < i_2<\dots<i_k}P(E_{i_1}E_{i_2}\dots E_{i_k}) - \sum_{i_1 < i_2<\dots<i_{k+1}}P(E_{i_1}E_{i_2}\dots E_{i_{k+1}}) + \dots + (-1)^{n-k}\sum_{i_1 < i_2<\dots<i_n}P(E_{i_1}E_{i_2}\dots E_{i_n}) + \dots + (-1)^{N-k}\sum_{i_1 < i_2<\dots<i_N}P(E_{1}E_{2}\dots E_{N})$$
question2: is the above formula correct?
Assuming that the above formulas are correct, the probability that at least $k$ of the party members receive their own hats back, comes out to be
$$\sum_{i=k}^N \frac{(-1)^{i-k}}{i!} = \frac{1}{k!} - \frac{1}{(k+1)!} + \frac{1}{(k+2)!} - \dots +(-1)^{N-k} \cdot \frac{1}{N!}$$
question 3: is this correct?
$ \text{ the probability that exactly k of the party members receive their own hats back is} $
$$||$$
$$\text{(the probability that at least k of the party members receive their own hats back)}$$ $$-$$ $$\text{(the probability that at least k+1 of the party members receive their own hats back)}$$
question4: is the above formula correct?
Assuming everything until now is correct, the probability that exactly $k$ of the party members receive their own hats back, comes out to be
$$= \bigg[\frac{1}{k!} - \frac{1}{(k+1)!} + \frac{1}{(k+2)!} - \dots +(-1)^{N-k} \cdot \frac{1}{N!} \bigg] - \bigg[ \frac{1}{(k+1)!} - \frac{1}{(k+2)!} + \dots +(-1)^{N-(k+1)} \cdot \frac{1}{N!} \bigg]$$
$$= \frac{1}{k!} - \frac{2}{(k+1)!} + \frac{2}{(k+2)!} - \dots +(-1)^{N-k} \cdot \frac{2}{N!}$$
but the given answer is
$$\frac{1}{k!} \cdot \sum_{i=0}^{N-k}\frac{(-1)^i}{i!}$$
so something is definitely wrong
What I want to ask: could you please answer questions 1, 2, 3 and 4?
edit: I know that a simple way to answer the question is to use the concept of derangements, which gives the answer as $$\frac{\binom{N}{k} D_{N - k}}{N!}$$, where $D_n = n! \cdot \sum_{i=0}^{n}\frac{(-1)^i}{i!}$
edit1: has been moved to a new question
 A: The first two formulas are correct, but the second one doesn’t appear to be at all useful in this problem. To see this, consider the case $n=1$: then that sum is $1$, which is not the probability of anything very useful. In fact that sum actually gives you the expected number of sets of $n$ men all of whom get their own hats back. For $n=1$ it tells you that the expected number of individuals who get their own hats back is $1$, a well-known result about derangements.
As a result, the inclusion-exclusion calculation is wrong from the start. To see how to do it right, we can reverse engineer the correct result. It’s a probability, and I find it easier to work with the actual counts, so I’ll begin by multiplying it by $N!$ to get the number of permutations that return their own hats to at least $k$ men. That results in $\frac{N!}{k!}\sum_{i=0}^{N-k}\frac{(-1)^i}{i!}$. I’d expect a summation arising from an inclusion-exclusion argument to involve at least one binomial coefficient, and $\frac{N!}{k!}$ is clearly $\binom{N}k(N-k)!$. Moreover, if we move the $(N-k)!$ inside the summation, we have $\frac{(N-k)!}{i!}$, so we can rewrite the whole thing as
$$\begin{align*}
\frac{N!}{k!}\sum_{i=0}^{N-k}\frac{(-1)^i}{i!}&=\binom{N}k\sum_{i=0}^{N-k}(-1)^i\binom{N-k}i(N-k-i)!\\
&=\binom{N}k\left((N-k)!-\sum_{i=1}^{N-k}(-1)^{i+1}\binom{N-k}i(N-k-i)!\right)\,.
\end{align*}$$
That final summation is typical of inclusion-exclusion calculations and in context has a fairly straightforward interpretation. Suppose that we’ve put aside a set $S$ of $k$ men who are to get their own hats back; there are $(N-k)!$ permutations that return their own hats to all $k$ of the men in $S$ (and possibly others as well). Let $T$ be the set consisting of the remaining $N-k$ men, and for each $i\in T$ let $A_i$ be the set of permutations also giving $i$ his own hat back. To get the number of permutations that return their own hats only to the $k$ men in $S$, we need to subtract $\left|\bigcup_{i\in T}A_i\right|$, and that’s exactly what we’ve done.
If $\varnothing\ne I\subseteq T$, there are $(N-k-|I|)!$ permutations that return their own hats to the men in $I$, and for each $i=1,\ldots,N-k$ there are $\binom{N-k}i$ subsets of $T$ with $i$ members. Thus,
$$\begin{align*}
\left|\bigcup_{i\in T}A_i\right|&=\sum_{\varnothing\ne I\subseteq T}(-1)^{|I|+1}\left|\bigcap_{i\in I}A_i\right|\\
&=\sum_{i=1}^{N-k}(-1)^{i+1}\binom{N-k}i(N-k-i)!\,,
\end{align*}$$
and it’s immediate that there are
$$(N-k)!-\sum_{i=1}^{N-k}(-1)^{i+1}\binom{N-k}i(N-k-i)!$$
permutations that return their own hats precisely to the $k$ members of $S$. Finally, there are $\binom{N}k$ sets of $k$ men, so there are
$$\binom{N}k\left((N-k)!-\sum_{i=1}^{N-k}(-1)^{i+1}\binom{N-k}i(N-k-i)!\right)\,,$$
or
$$\frac{N!}{k!}\sum_{i=0}^{N-k}\frac{(-1)^i}{i!}$$
permutations that return their own hats to exactly $k$ of the men. Dividing by $N!$ yields the probability of this event. (You could work directly with the corresponding probabilities instead; I just find it easier this way.)
