-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathN2579.cpp
More file actions
80 lines (60 loc) · 1.09 KB
/
Copy pathN2579.cpp
File metadata and controls
80 lines (60 loc) · 1.09 KB
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
#include <iostream>
#define FASTIO cin.tie(nullptr); ios::sync_with_stdio(false);
using namespace std;
int N;
int stair[301],dp[301];
int main(){
FASTIO;
cin >> N;
for (int i = 1; i <= N; i++) {
cin >> stair[i];
}
dp[1] = stair[1];
dp[2] = stair[1] + stair[2];
dp[3] = stair[3] + max(stair[1], stair[2]);
for (int i = 4; i <= N; i++) {
dp[i] = stair[i] + max(dp[i - 2], dp[i - 3] + stair[i - 1]);
}
cout << dp[N] << "\n";
return 0;
}
/*
#include <iostream>
#define FASTIO cin.tie(nullptr); ios::sync_with_stdio(false);
using namespace std;
int N;
int stair[301];
int result = 0;
int main(){
FASTIO;
cin >> N;
for (int i = 1; i <= N; i++) {
cin >> stair[i];
}
int duplication = 0;
while (N > 0) {
if (result == 0) {
result += stair[N];
N--;
duplication++;
}
else if (stair[N] >= stair[N - 1] || N==1) {
result += stair[N];
N--;
duplication++;
}
else {
result += stair[N - 1];
N -= 2;
duplication;
}
if (duplication == 2) {
result += stair[N - 1];
N -= 2;
duplication = 0;
}
}
cout << result << "\n";
return 0;
}
*/