提交时间:2023-12-16 08:54:00
运行 ID: 116164
#include <bits/stdc++.h> using namespace std; int max(int x,int y) { if(x>y) { return x; } if(x<=y) { return y; } } int main() { int a; cin>>a; int byd[a+1],dp[a+1]; for (int i = 1;i <= a;i++) { cin>>byd[i]; dp[i]=0; } dp[0]=0; dp[1]=byd[1]; for (int i = 2; i<=a; i++) { dp[i]=max(dp[i-1],(byd[i]+dp[i-2])); } cout<<dp[a]; return 0; }