Friend's Pairing

Didn’t understand why we did (n-1)*f(n-2)

The complete formula is -

dp[n] = dp[n-1] + (n-1)*dp[n-2]

When a person decides to go alone, the answer will come from dp[n-1].
If he/she decides to go in a pair, we have to choose one person from the remaining (n-1) people which will be done in n-1 ways. And we have to multiply this (n-1) with dp[n-2]. dp[n-2] gives the number of ways in which the remaining people can go to the party.