-
Notifications
You must be signed in to change notification settings - Fork 0
/
contestC.cpp
78 lines (61 loc) · 1.65 KB
/
contestC.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
#include <bits/stdc++.h>
using namespace std;
#define SPEED cin.tie(0)->sync_with_stdio(0);
#define DEBUG true
#define db(x) \
if (DEBUG) cout << #x << ": " << x << endl
#define dbpair(x) \
if (DEBUG) cout << #x << ": " << x.f << ", " << x.s << endl
#define dbvector(vector) \
{ \
cout << #vector << " = "; \
for (auto& it : vector) cout << it << " "; \
cout << endl; \
}
#define dbmap(map) \
for (auto e : map) \
cout << e.first << " " << e.second; \
cout << endl
#define all(x) begin(x), end(x)
#define pb push_back
#define pf push_front
#define endl "\n"
#define f first
#define s second
#define MOD 1e9 + 7
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;
const int MAXN = 262'200;
int n;
vector<int> moedas;
vector<int> memo;
int dp(int k) {
if(k >= n) {
if(k == n) return moedas[k];
return 0;
}
auto &p = memo[k];
if(p != -1) return p;
auto dobro = moedas[k] + dp(2 * k);
auto dobro_mais_um = moedas[k] + dp((2 * k) + 1);
return p = max(dobro, dobro_mais_um);
}
int main(int argc, char** argv) {
SPEED;
int aux; cin >> aux;
n = pow(2, aux) - 1;
moedas.resize(MAXN);
memo.assign(MAXN, -1);
for(int i = 1; i <= n; i++) {
cin >> moedas[i];
}
cout << dp(1) << endl;
return 0;
}