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 ...
随机推荐
- python基础之1-安装
author:headsen chen date :2018-03-22 17:16:14 notice :This article created by headsen chen and no ...
- PHP获取当前日期和时间格式化方法
使用函式 date() 实现 <?php echo $showtime=date("Y-m-d H:i:s");?> 显示的格式: 年-月-日 小时:分钟:妙 相关时间 ...
- 一文彻底解决Ubuntu上PHP的安装以及版本切换
Ubuntu上官方的源,比如 Ubuntu14.04 默认源中的是 PHP5.6.x.Ubuntu16.04 默认源中的是 PHP7.0.x,那么如果想在 Ubuntu16.04 上安装 PHP7.1 ...
- win7卸载IE11
好多人升级了IE11后发现各种不好用,比如经常卡死,无响应.调试工具不好用等缺点. 现在告诉你如何卸载IE11 查看已安装的更新 右键wie卸载,即可需要重启
- R中基本命名(未完)
ls() #查看 rm(list=ls()) #清除内存变量 library() #载入库包 help() #查看帮助文档 head(iris) #查看数据集 class(iris) #查看数据集的类 ...
- MongoDB 使用 ObjectId 代替时间
An ObjectId is a 12-byte unique identifier consisting of: a 4-byte value representing the seconds si ...
- yum install mysql on centos 6.5 zz
http://www.cnblogs.com/xiaoluo501395377/archive/2013/04/07/3003278.html 1.使用yum命令进行mysql的安装 yum list ...
- SDUT1607:Number Sequence(矩阵快速幂)
题目:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1607 题目描述 A number seq ...
- Appium-Java滑动操作
Java滑动操作,通常可以直接使用API中AndroidDriver类中的swipe方法,直接进行调用 swipe(int startx, int starty, int endx, int endy ...
- mysql在线手册汇总
1. MySQL官网 http://www.mysql.com/ • Reference Manual ▶ MySQL 5.0 Reference Manual:http://dev.mysql.co ...