-
Notifications
You must be signed in to change notification settings - Fork 0
/
2579.cpp
61 lines (55 loc) · 955 Bytes
/
2579.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
#include <iostream>
#include <vector>
using namespace std;
int res = 0;
int n;
int flag = 0;
void DP(vector<int> &v)
{
if (flag == 1)
{
res += v[n - 2];
n = n - 2;
flag = 0;
}
else
{
// 같은 것도 고려해야됨 ~~~ 3 30 30 10
// cout << "현재 v:" << n << ":" << v[n] + v[n - 1] << ", " << v[n] + v[n - 2] << '\n';
if (v[n] + v[n - 1] > v[n] + v[n - 2])
{
res += v[n - 1];
flag++;
n--;
}
else
{
res += v[n - 2];
n = n - 2;
flag = 0;
}
}
if (n - 1 >= 0)
DP(v);
else
{
return;
}
}
int main()
{
cin >> n; // 계단 개수
vector<int> v(n + 1);
for (int i = 1; i <= n; i++)
{
cin >> v[i]; // 계단 data
}
if (n == 1)
{
cout << v[1];
return 0;
}
res = v[n];
DP(v);
cout << res;
}