#include #include #include using namespace std; int main() { /* 任意の位置iの皿の合計値の最大 Take[i] = max(No_Take[i - 1] + v[i],Take[i - 2] + v[i]) No_Take[i] = max(Take[i - 1],Take[i - 2]) */ int Take[1001] = { 0 }; int No_Take[1001] = { 0 }; int num; cin >> num; vector v; for (int i = 0; i < num; i++) { int temp; cin >> temp; v.push_back(temp); } if (num == 1) { cout << v[0] << endl; return 0; } Take[0] = v[0];Take[1] = v[1];No_Take[0] = 0; No_Take[1] = v[0]; for (int i = 2; i < num;i++) { Take[i] += max(No_Take[i - 1] + v[i], Take[i - 2] + v[i]); No_Take[i] += max(Take[i - 1], Take[i - 2]); } cout << max(Take[num - 1], No_Take[num - 1]) << endl; return 0; }