Originally Posted by
Soroban Hello, phillipshwong!
The problem is badly worded.
Perhaps it was written by an amateur, a student . . .
I think I understand their reasoning . . .
$\displaystyle \,n$ people get their hats back.
The other $\displaystyle N-n$ people may or may not get their hats back.
. . And there are $\displaystyle (N-n)!$ ways to return those hats.
This is very sloppy work!
If they meant exactly $\displaystyle \,n$ get their hats,
. . the problem is more complicated.
$\displaystyle \text{There are: }\:_NC_n \:=\:{N\choose n}\text{ ways to select the }n \text{ lucky people.}$
The original problem did not consider this.
The other $\displaystyle N-n$ people must not get their own hats.
. . This is derangement of the $\displaystyle N-n$ hats,
. . which can be written: $\displaystyle d(N-n).$
Example:
. . 8 people, 8 hats.
. . Find the number of ways that exactly 3 get their hats.
There are: .$\displaystyle _8C_3 \:=\:{8\choose3} \:=\:56$ choices of the 3 people.
The other 5 people must not get their own hats.
. . There are: .$\displaystyle d(5) \:=\:44$ ways. .**
Therefore, there are: .$\displaystyle 56\cdot44 \:=\:2464$ ways.
**
The Derangement Formula is a topic best left for a separate lesson.
Or you can do a search for "derangement".