CF1155D Beautiful Array(动态规划)
做法
\(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(动态规划)的更多相关文章
- CF1155D Beautiful Array 贪心,dp
CF115DBeautiful Array 题目大意:给一个有n个元素的a数组,可以选择其中一个区间的所有数都乘上x,也可以不选,求最大子序列和. 如果没有前面的操作,就是只求最大子序列和,我们都知道 ...
- [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 ...
- [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 ...
- 漂亮数组 Beautiful Array
2019-04-06 16:09:56 问题描述: 问题求解: 本题还是挺有难度的,主要是要考虑好如何去进行构造. 首先考虑到2 * A[i] = A[j] + A[k],那么j,k就必须是同奇同偶, ...
- LeetCode - Beautiful Array
For some fixed N, an array A is beautiful if it is a permutation of the integers 1, 2, ..., N, such ...
- Educational Codeforces Round 63 D. Beautiful Array
D. Beautiful Array time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- 932. Beautiful Array
For some fixed N, an array A is beautiful if it is a permutation of the integers 1, 2, ..., N, such ...
- 北邮校赛 I. Beautiful Array(DP)
I. Beautiful Array 2017- BUPT Collegiate Programming Contest - sync 时间限制 1000 ms 内存限制 65536 KB 题目描述 ...
- 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 ...
随机推荐
- 最受欢迎的五大BUG管理系统
五大最受欢迎的BUG管理系统 Google在中国大*陆遭遇变故做出暂时性的退出大*陆市场,也使很多忠实的用户受到小小的挫折,以本公司为例,原本的BUG都是记录在google的EXCEL在线文档中 ...
- HDU 5701 中位数计数 百度之星初赛
中位数计数 Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Sub ...
- 第九课——MySQL优化之索引和执行计划
一.创建索引需要关注什么? 1.关注基数列唯一键的数量: 比如性别,该列只有男女之分,所以性别列基数是2: 2.关注选择性列唯一键与行数的比值,这个比值范围在0~1之前,值越小越好: 其实,选择性列唯 ...
- python celery rabbitmq--- pypi image from ustc
https://lug.ustc.edu.cn/wiki/mirrors/help/pypi 那么为啥要用celery ?(http://xiaorui.cc/2014/11/16/celery-ra ...
- 关于一个非常非常无语的bug,与君共勉
今天,哦,不对,是昨天晚上,我花了大概四十分钟去找一个bug,结果还没找到 错误代码" $('#sendAreaInfo').citypicker('reset'); $('#sendAre ...
- zipline风险指标计算 (empyrical模块)
概述 量化中,我们经常会遇到各种量化指标的计算,对于zipline来说,也会对这部分计算进行处理,由于指标计算的通用性比较强,所以,zipline单独封装了 empyrical 这个模块,可以处理类似 ...
- python基础-第七篇-7.3反射
定义 反射是根据字符串的形式去对操作其成员 了解反射前,我先看看内置方法__import__,还记得这个内置方法吗? __import__ 用于以字符串的形式导入模块 inp = input('请输 ...
- 前端开发 - jsBom
一.jsBom简介 jsBom = javascript browser object modelBOM指的是浏览器对象模型 Browser Object Model,它的核心就是浏览器. 二.Bom ...
- 一行代码让python的运行速度提高100倍
python一直被病垢运行速度太慢,但是实际上python的执行效率并不慢,慢的是python用的解释器Cpython运行效率太差. “一行代码让python的运行速度提高100倍”这绝不是哗众取宠的 ...
- sql server dba概念系列引用
原文转自:https://www.cnblogs.com/gaochundong/p/everyone_is_a_dba_sqlserver_architecture.html <人人都是 DB ...