提交时间:2023-12-16 09:02:34

运行 ID: 116188

#include <bits/stdc++.h> using namespace std; vector<int> nums(2023); int n; int xiaoJB(int start, int end) { if (end == start) return nums[start]; vector<int> dp(n); dp[start] = nums[start]; dp[start + 1] = max(nums[start], nums[start + 1]); for (int i = start + 2; i <= end; i++) { dp[i] = max(dp[i - 2] + nums[i], dp[i - 1]); } return dp[end]; } int main() { cin>>n; for(int i=0;i<n;i++) cin>>nums[i]; if (n == 0){ cout<<0; exit(0); } if (n == 1){ cout<<nums[0]; exit(0); } int result1 = xiaoJB(0, n - 2); int result2 = xiaoJB(1, n - 1); cout<<max(result1, result2)<<endl; }