做法

\(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. 160309、Spring AOP操作action时无法注入,报空指针错误

    今天帮同事看个问题,action注入失败,代码没问题,主要是stuts2权限移交的问题,特此记录一下 Spring AOP操作action时无法注入,报NullPointer异常 当使用Spring ...

  2. [ Office 365 开发系列 ] 前言

    前言 本人从接触Microsoft SharePoint Server 2007到目前为止,已经在微软SharePoint的路上已经走了好几年,基于SharePoint平台的特殊性,对微软产品线都有了 ...

  3. style,currentStyle和getComputedStyle的区别

    样式表有三种方式 内嵌样式(inline Style) :是写在Tag里面的,内嵌样式只对所有的Tag有效. 内部样式(internal Style Sheet):是写在HTML的里面的,内部样式只对 ...

  4. 可序列化对象和byte[]数组之间的互转

    /// <summary> /// 将可序列化对象转成Byte数组 /// </summary> /// <param name="obj">对 ...

  5. 关于LegacyExchangeDN的问题

    IMCEAEX i NDR This problem is not common but quite annoying and usually hard to understood by users. ...

  6. FormsAuthentication 使用指南

    配置安全鉴别 鉴别是指鉴定来访用户是否合法的过程.ASP.NET Framework支持三种鉴别类型: Windows鉴别: NET Passport鉴别: Forms鉴别. 对于某一特定的应用程序, ...

  7. linux系统分析命令总结

    一张图片

  8. Linux/Mac里复制终端Session(像SecureCRT一样)

    在你的登录账户下的.ssh文件夹新建一个文件:config cd ~/.ssh config的文件中,内容为: host * ControlMaster auto ControlPath ~/.ssh ...

  9. GraphicsMagick 1.3.25 Linux安装部署

    1.安装相关依赖包 yum install -y gcc libpng libjpeg libpng-devel libjpeg-devel ghostscript libtiff libtiff-d ...

  10. LeetCode—Longest Consecutive Sequence

    题目描述: Given an unsorted array of integers, find the length of the longest consecutive elements seque ...