File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change
1
+ long long dp[105];
2
+ long long comb[105][105];
3
+ #define MOD 1000000007
4
+ int rec(int n)
5
+ {
6
+ if(n<=1)
7
+ return 1;
8
+ if(dp[n] != -1)
9
+ return dp[n];
10
+ int i;
11
+ int fill = 0;
12
+ int pw = 2;
13
+ int left,right;
14
+ left = right = 0;
15
+
16
+ while(fill+pw < n-1)
17
+ {
18
+ fill += pw;
19
+ left += pw/2;
20
+ right += pw/2;
21
+ pw *= 2;
22
+ }
23
+ int rem = n-1-fill;
24
+ if(rem > pw/2)
25
+ {
26
+ left += pw/2;
27
+ right += (rem-pw/2);
28
+ }
29
+ else
30
+ left += rem;
31
+ //cout<<"solve "<<n<<" left = "<<left<<" right = "<<right<<" ";
32
+ return dp[n] = (((rec(left)*1LL*rec(right))%MOD)*1LL*comb[n-1][left])%MOD;
33
+
34
+ }
35
+ int Solution::solve(int A)
36
+ {
37
+ int i,j;
38
+ for(i=0;i<=100;i++)
39
+ dp[i] = -1;
40
+ comb[0][0] = 1;
41
+ for(i=1;i<=100;i++)
42
+ {
43
+ comb[i][0] = comb[i][i] = 1;
44
+ for(j=1;j<i;j++)
45
+ comb[i][j] = (comb[i-1][j-1]+comb[i-1][j])%MOD;
46
+ }
47
+ return rec(A);
48
+ }
You can’t perform that action at this time.
0 commit comments