做法

\(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. 构建API

    前言 过程,如图: 第一步创建一个帮助类,类里面提供了加密.组装Url等方法,代码如下: using System; using System.Collections.Generic; using S ...

  2. 从0到1实现SourceTree连接Gitlab

    见下面的链接 http://note.youdao.com/noteshare?id=3622d02a38464c524222ede1b4fb06d2 SourceTree下载地址:Windows V ...

  3. HDU 5667 Sequence(矩阵快速幂)

    Problem Description Holion August will eat every thing he has found. Now there are many foods,but he ...

  4. userAgent font-family

    w view-source:http://you.163.com/ CODE <script type="text/javascript"> (function () ...

  5. python学习笔记(二)— 字符串(string)

    字符串是 Python 中最常用的数据类型.我们可以使用引号('或")来创建字符串. 创建字符串很简单,只要为变量分配一个值即可.例如: var1 = 'Hello World!' var2 ...

  6. c++主程这种事情,就是这样,看人先看人品,没人品,他的能力与你何关?

    这就是人品的重要性........ 接手别人的代码,说困难,也困难,说容易也容易 想把别人代码都读通,理顺,在改原代码BUG,在完美的加功能,那项目越大,越难 想把别人代码里面,加点坑,随便找个模块, ...

  7. 原!linux 监控 jar定时任务 挂了重启 脚本

    #!/bin/bash time=$(date "+%Y-%m-%d %H:%M:%S") echo "monitor start at: ${time}" P ...

  8. Power Strings----poj2406(kmp扩展 循环节)

    题目链接:http://poj.org/problem?id=2406 题意:就是求串s能够最多由多少个相同的串a串联而成: 例如 ababab 由3个ab串联而成: abababa 只能由1个aba ...

  9. Django中对静态文件的支持(转)

    英文原文:[http://agiliq.com/blog/2013/03/serving-static-files-in-django/] 译文:[http://segmentfault.com/a/ ...

  10. ovn-kubernetes执行流程概述

    Master部分 1.master初始化 以node name创建一个distributed logical router 创建两个load balancer用于处理east-west traffic ...