Hey @artendhiim1337 Let me explain the approach for you.
So we will try to solve this problem using dynamic programming(bottom-up approach).
Now for the person with index i, he has 2 choices ,either he can remain single and simply add up to already existing combinations up until index i-1 ,i.e, dp[i-1] or he can shake hands with some person and remaining i-2 persons can be arranged according to dp[i-2] ways. Now the person who i will pair up with can be chosen in i-1 ways.
So our loop would look something like this :-
dp[i]=dp[i-1]+(i-1)*dp[i-2];
We need to initialise dp[1]=1,dp[2]=2.
If you still have any further queries please feel free to ask,otherwise kindly mark the doubt as resolved