#include <iostream>
#include <algorithm>
using namespace std;
int m;
int stairscore[301];
int staircopy[301];
int maxscore() {
staircopy[1] = stairscore[1];
staircopy[2] = stairscore[1] + stairscore[2];
staircopy[3] = max(stairscore[1] + stairscore[3], stairscore[2] + stairscore[3]);
for (int i = 4; i <= m; i++) {
staircopy[i] = max(staircopy[i - 2] + stairscore[i], stairscore[i - 1] + stairscore[i] + staircopy[i - 3]);
}
return staircopy[m];
}
int main(void) {
cin >> m;
for (int i = 1; i <= m; i++) {
cin >> stairscore[i];
}
cout << maxscore();
}
'백준 알고리즘 > 다이나믹 프로그래밍' 카테고리의 다른 글
백준 2156번 C++ (0) | 2019.01.15 |
---|---|
백준 11726번 C++ (0) | 2019.01.15 |
백준 2193번 C++ (0) | 2019.01.14 |
백준 9095번 C++ (0) | 2019.01.14 |
백준 5014번 C++ (0) | 2019.01.14 |