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