简答题
偏难
#12918
宝可梦
宝可梦


答案与解析
正确答案:<pre class="brush:cpp;toolbar:false">#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
ll dp0 = 0, dp1 = -INF;
for (int i = 0; i < n; ++i)
{
ll x;
cin >> x;
ll nd0 = dp0, nd1 = dp1; // 不放走:原样继承
// 选择击败进行状态更新
nd0 = max(nd0, dp1 + 2 * x);
nd1 = max(nd1, dp0 + x);
dp0 = nd0; dp1 = nd1;
}
cout << max(dp0, dp1) << '\n';
return 0;
}</pre>
这道题暂未补解析。