首页 › 题库 › C/C++编程考级 › C/C++编程六级 › 简答题
简答题 偏难
#12918

宝可梦

宝可梦

image7.png

image8.png

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