There are N people. All with their own, unique hat. Each throw his hat into a pile, and mix it. The number of ways for n < N to get their hats is ( N-n)!. Why?
To understand these problems I take N to be a smallish number i.e. N=3, then find the number of arrangements for n=1,2.
Then take N=4 and find the number of arrangements for n=1,2,3
Finally take N=5 and find the number of arrangements for n=1,2,3,4 you'll start to see the pattern.
;D

Hello, phillipshwong!
The problem is badly worded.
Perhaps it was written by an amateur, a student . . .
![]()
I think I understand their reasoning . . .
people get their hats back.
The otherpeople may or may not get their hats back.
. . And there areways to return those hats.
This is very sloppy work!
If they meant exactlyget their hats,
. . the problem is more complicated.
The original problem did not consider this.
The otherpeople must not get their own hats.
. . This is derangement of thehats,
. . which can be written:
Example:
. . 8 people, 8 hats.
. . Find the number of ways that exactly 3 get their hats.
There are: .choices of the 3 people.
The other 5 people must not get their own hats.
. . There are: .ways. .**
Therefore, there are: .ways.
**
The Derangement Formula is a topic best left for a separate lesson.
Or you can do a search for "derangement".