提交时间:2023-12-16 08:53:54
运行 ID: 116163
#include<bits/stdc++.h> using namespace std; const int maxn = 1005; int dp[maxn], a[maxn]; int main(){ int n, sum = 0; cin >> n; for (int i = 1; i <= n; i++){ cin >> a[i]; } dp[1] = a[1]; dp[2] = a[2]; for (int i = 3; i <= n; i ++){ dp[i] = max(dp[i - 2] + a[i], dp[i - 1]); } cout << dp[n]; }