-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathHandshakes.cpp
50 lines (34 loc) · 870 Bytes
/
Handshakes.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
Solution by Rahul Surana
***********************************************************
We have N persons sitting on a round table. Any person can do a handshake with any other person.
***********************************************************
*/
// { Driver Code Starts
#include<bits/stdc++.h>
using namespace std;
// } Driver Code Ends
class Solution{
public:
int count(int N){
if(N%2 == 1) return 0;
if(N == 0||N==2) return 1;
int ans = 0;
for(int i = 0; i < N; i+=2) ans += count(i)*count(N-2-i);
return ans;
}
};
// { Driver Code Starts.
int main()
{
int t;
cin>>t;
while(t--)
{
int N;
cin>>N;
Solution ob;
cout << ob.count(N) << endl;
}
return 0;
} // } Driver Code Ends