-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path5737.cpp
More file actions
52 lines (41 loc) · 692 Bytes
/
5737.cpp
File metadata and controls
52 lines (41 loc) · 692 Bytes
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
#include <iostream>
using namespace std;
int input;
long long pills[40][40];
long long calc(int whole, int half);
int main()
{
calc(30, 0);
while(cin >> input)
{
if(input)
{
cout << pills[input][0] << endl;
}
else
{
break;
}
}
return 0;
}
long long calc(int whole, int half)
{
if(pills[whole][half] > 0)
{
return pills[whole][half];
}
if(whole == 0)
{
pills[whole][half] = 1;
return pills[whole][half];
}
if(half == 0)
{
calc(whole - 1, half + 1);
pills[whole][half] = calc((whole - 1), (half + 1));
return pills[whole][half];
}
pills[whole][half] = calc((whole - 1), (half + 1)) + calc(whole, (half - 1));
return pills[whole][half];
}