做法

\(f_{i,0}\)表示以\(i\)结尾未操作时的最大值

\(f_{i,1}\)表示以\(i\)结尾正在操作时的最大值

\(f_{i,2}\)表示以\(i\)结尾已结束操作时的最大值

Code

#include<bits/stdc++.h>
typedef long long LL;
const int maxn=1e6+9;
LL ans,n,x;
LL a[maxn],f[maxn][3];
int main(){
std::cin>>n>>x;
for(LL i=1;i<=n;++i){
std::cin>>a[i];
f[i][0]=std::max(f[i-1][0]+a[i],0LL);
f[i][1]=std::max(f[i-1][1]+a[i]*x,f[i][0]);
f[i][2]=std::max(f[i-1][2]+a[i],f[i][1]);
ans=std::max(ans,f[i][2]);
}
std::cout<<ans;
}

CF1155D Beautiful Array(动态规划)的更多相关文章

  1. CF1155D Beautiful Array 贪心,dp

    CF115DBeautiful Array 题目大意:给一个有n个元素的a数组,可以选择其中一个区间的所有数都乘上x,也可以不选,求最大子序列和. 如果没有前面的操作,就是只求最大子序列和,我们都知道 ...

  2. [Educational Codeforces Round 63 ] D. Beautiful Array (思维+DP)

    Educational Codeforces Round 63 (Rated for Div. 2) D. Beautiful Array time limit per test 2 seconds ...

  3. [Swift]LeetCode932. 漂亮数组 | Beautiful Array

    For some fixed N, an array A is beautiful if it is a permutation of the integers 1, 2, ..., N, such ...

  4. 漂亮数组 Beautiful Array

    2019-04-06 16:09:56 问题描述: 问题求解: 本题还是挺有难度的,主要是要考虑好如何去进行构造. 首先考虑到2 * A[i] = A[j] + A[k],那么j,k就必须是同奇同偶, ...

  5. LeetCode - Beautiful Array

    For some fixed N, an array A is beautiful if it is a permutation of the integers 1, 2, ..., N, such ...

  6. Educational Codeforces Round 63 D. Beautiful Array

    D. Beautiful Array time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  7. 932. Beautiful Array

    For some fixed N, an array A is beautiful if it is a permutation of the integers 1, 2, ..., N, such ...

  8. 北邮校赛 I. Beautiful Array(DP)

    I. Beautiful Array 2017- BUPT Collegiate Programming Contest - sync 时间限制 1000 ms 内存限制 65536 KB 题目描述 ...

  9. LC 932. Beautiful Array

    For some fixed N, an array A is beautiful if it is a permutation of the integers 1, 2, ..., N, such ...

随机推荐

  1. VS2013新特性

    大家可能看到我这边颜色和字体和原本不同,这里特意分享给大家背景护眼色值(这对每天看电脑的程序员很重要对不对!)还有字体: 工具-选项-字体和颜色:在项背景点击自定义-色调85 饱和度123 亮度205 ...

  2. __construct __destory __call __get __set

    1,__construct() 当实例化一个对象的时候,这个对象的这个方法首先被调用. 我们知道 php5对象模型 < ,所以__construct()作为类的默认的构造函数 而不会调用同类名函 ...

  3. Django学习笔记第十二篇--关于自定义数据库字段数据类型

    一.需求背景: django的models模块提供了很多数据字段的数据类型field,但是总有写奇葩需求不能依靠默认字段满足,所以需要自定义数据数据库数据字段类型.所有的自定义field应该在app路 ...

  4. ios 将p12文件转换为pem

    cd 到 文件所在目录 执行以下命令,生成ck.pem文件. openssl pkcs12 -in ck.p12 -out ck.pem -nodes

  5. EditText监听方法,实时的判断输入多少字符

    最近在写一个小项目,其中有一点用到了显示EditText中输入了多少个字符,像微博中显示剩余多少字符的功能.在EditText提供了一个方法addTextChangedListener实现对输入文本的 ...

  6. Location 对象的assign()和replace()有什么区别?

    window.location.assign(url) : 加载 URL 指定的新的 HTML 文档. 就相当于一个链接,跳转到指定的url,当前页面会转为新页面内容,可以点击后退返回上一个页面. w ...

  7. java的list集合如何根据对象中的某个字段排序?

    转自:http://blog.csdn.net/wangjuan_01/article/details/51351633 List集合按某个字段排序 package wjtest_01; import ...

  8. green rgb(255, 102, 0) #FF6600

    w通过元素背景色定位元素,改变其属性. style="background-color: #FF6600" <script> var w = document.quer ...

  9. Spark Streaming Programming Guide

    参考,http://spark.incubator.apache.org/docs/latest/streaming-programming-guide.html Overview SparkStre ...

  10. Tomcat 下 mysql的连接池配置和使用

    最近维护的一个项目出了问题,最后分析是卡在数据库连接池上,然后就做了些学习. 先把我自己的方法写出来,再说下网上其他的没有成功的方法. 1.首先当然是先把mysql的jar包放在lib目录下,tonc ...