I got the following question and would very much appreciate any help with understanding it solution.
"5 Student cards are handed to 5 students so that each student gets 1 student card, what is the number of options if exactly 1 student gets his right student card and the others each get a student card that isn't theirs?"
For simplicity, let's assume all five students are male. Line the students up in alphabetical order. There are five ways for a particular student to receive his correct student card.
There are four more cards to distribute, which can be distributed in $4!$ ways since we have lined up the students in alphabetical order. We must exclude those arrangements in which one or more of these students receives his own student card. The number of ways at least $k$ of the other $4$ students can receive his/their own student cards is $\binom{4}{k}(4 - k)!$ since there are $\binom{4}{k}$ ways of selecting the $k$ students who receive his/their own cards and $(4 - k)!$ orders in which the remaining $4 - k$ cards can be distributed to the remaining $4 - k$ students. By the Inclusion-Exclusion Principle, the number of ways four student cards can be distributed so that no student receives his own student card is \begin{align*} 4! - \binom{4}{1} \cdot 3! + \binom{4}{2} \cdot 2! - \binom{4}{3} \cdot 1! + \binom{4}{4} \cdot 0! & = 24 - 4 \cdot 6 + 6 \cdot 2 - 4 \cdot 1 + 1 \cdot 1\\ & = 24 - 24 + 12 - 4 + 1\\ & = 9 \end{align*} This is a derangement of four elements. The number of derangements of $n$ elements is denoted $D_n$ or $!n$, so we have used the Inclusion-Exclusion Principle to show that $D_4 = 9$.
Since there are five ways to give one of the students his correct student card and nine ways to distribute the four remaining student cards in such a way that none of the other four students receives his own card, the number of ways the student cards can be distributed so just one of the five students receives his correct student card is $5 \cdot D_4 = 5 \cdot 9 = 45$.