-
Notifications
You must be signed in to change notification settings - Fork 0
/
12.COINS.cpp
49 lines (38 loc) · 818 Bytes
/
12.COINS.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
#include<bits/stdc++.h>
using namespace std;
#define max2(a, b) (((a) > (b)) ? (a) : (b))
#define min2(a, b) (((a) > (b)) ? (b) : (a))
#define abs(a) (((a) > 0) ? (a) : (-(a)))
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
const int INF = 0x3f3f3f3f;
typedef long long ll;
typedef unsigned long int ult;
map <int, ll> h;
ll getmaxval(ll val)
{
if(val == 0) return 0;
ll r = h[val];
if(r == 0)
{
r = max(val, getmaxval(val / 2) + getmaxval(val / 3) + getmaxval(val / 4));
h[val] = r;
}
return r;
}
int main()
{
ll n;
vector<ll> val;
while(cin>>n)
{
val.push_back(n);
}
int len = val.size();
for(int i = 0; i < len; i++)
{
h.clear();
cout<<getmaxval(val[i])<<endl;
}
return 0;
}