forked from sameer2800/Lightoj-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path1173-the_vindictive_coach.cpp
113 lines (87 loc) · 1.82 KB
/
1173-the_vindictive_coach.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include <bits/stdc++.h>
#define ll unsigned long long
#define MAX 100100
using namespace std;
ll f[60][60] ; // f(a,b) => a contains count of smaller elements , b contains
ll g[60][60]; // number of larger elements.f(a,b) chosing element from a.
ll mod;
ll recursive_gdp(ll mins, ll maxs);
ll recursive_fdp(ll mins, ll maxs)
{
if (mins == 1 and maxs == 0) {
f[mins][maxs] = 1;
return 1;
}
if (mins == 0) {
f[mins][maxs] = 0;
return 0;
}
if (mins < 0 || maxs < 0)
return 0;
if (f[mins][maxs] != -1)
return f[mins][maxs];
ll temp = 0;
for (int k = 0; k < mins; k++) {
temp += recursive_gdp(k, maxs + mins - 1 - k);
}
f[mins][maxs] = temp;
return temp;
}
ll recursive_gdp(ll mins, ll maxs)
{
if (mins == 0 and maxs == 1) {
g[mins][maxs] = 1;
return 1;
}
if (maxs == 0) {
g[mins][maxs] = 0;
return 0;
}
if (mins < 0 || maxs < 0)
return 0;
if (g[mins][maxs] != -1)
return g[mins][maxs];
ll temp = 0;
for (int k = 0; k < maxs; k++) {
temp = (temp + recursive_fdp( mins + (maxs - 1 - k), k)) ;
}
g[mins][maxs] = temp;
return temp;
}
void dptable()
{
memset(f, -1, sizeof f);
memset(g, -1, sizeof g);
f[1][0] = 1;
g[0][1] = 1;
for (int i = 0; i < 55; i++) {
for (int j = 0; j < 55; j++) {
f[i][j] = recursive_fdp(i, j);
g[i][j] = recursive_gdp( i, j);
}
}
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("/home/sameer/Documents/sameer/input.sam", "r", stdin);
#endif
ios_base::sync_with_stdio(false);
ll i, j, k, n, m, t, cont, a, b;
dptable();
cin >> t;
ll cases = t;
while (t--) {
cin >> n >> m;
if (m != 1) {
cout << "Case " << cases - t << ": " << f[m - 1][n - m] << endl;
}
else {
if (n >= 3)
cout << "Case " << cases - t << ": " << f[1][n - 3] << endl;
else
cout << "Case " << cases - t << ": " << "1" << endl;
}
}
return 0;
}