https://www.acmicpc.net/problem/2156
#include <iostream>
using namespace std;
const int MAX = 10003;
int num[MAX];
int n;
int solution(){
int dp[MAX] ={0, };
int answer = 0;
for(int i=3;i<n+3;i++){
dp[i] = max(dp[i-3] + num[i-1], dp[i-2]) + num[i];
dp[i] = max(dp[i-1], dp[i]);
answer = max(answer, dp[i]);
}
return answer;
}
int main(){
cin>>n;
for(int i=3;i<n+3;i++){
cin>>num[i];
}
cout<<solution()<<endl;
return 0;
}
#include<cstdio>
#include<algorithm>
using namespace std;
int dp[3], tmp;
int main()
{
int n, x;
scanf("%d", &n);
while (n--)
{
scanf("%d", &x);
tmp = max(dp[0], max(dp[1], dp[2]));
if (dp[1]) dp[2] = dp[1] + x;
dp[1] = dp[0] + x;
dp[0] = tmp;
}
printf("%d\n", max(dp[0], max(dp[1], dp[2])));
}