https://codeforces.com/contest/1155/problem/D

这个题目还是不会写,挺难的,最后还是lj大佬教我的。

这个题目就是要分成三段来考虑,

第一段就是不进行乘,就是直接求这一个区间的最大的一段区间的最大值。

第二段就是后面有一部分进行乘法,前面有一部不进行乘法。这个也同样求一个区间的最大值。

第三段就是前面有一部分和后面有一部分不进行乘法,中间有一部分进行乘法,同样求这个区间的最大值。

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<queue>
#include<vector>
#define inf 0x3f3f3f3f
#define debug(x) cout<<"-----"<<" x = "<<x<<"-----"<<endl
using namespace std;
typedef long long ll;
const int maxn = 3e5 + ;
ll dp1[maxn], dp2[maxn], dp3[maxn];
ll a[maxn]; ll max_(ll x,ll y,ll z)
{
ll ans = max(x, y);
return max(ans, z);
} int main()
{
int n, k;
ll ans = ;
scanf("%d%d", &n, &k);
for (int i = ; i <= n; i++) scanf("%lld", &a[i]);
for (int i = ; i <= n; i++)
{
dp1[i] = a[i] + max(1ll * , dp1[i - ]);
ans = max(ans,dp1[i]);
}
for (int i = ; i <= n; i++)
{
dp2[i] = a[i] * k + max_(dp1[i - ], dp2[i - ],);
ans = max(dp2[i], ans);
}
dp3[] = dp2[] + a[];
ans = max(ans, dp3[]);
for (int i = ; i <= n; i++)
{
dp3[i] = a[i] + max_(dp2[i - ], dp3[i - ],);
ans = max(ans, dp3[i]);
}
printf("%lld\n", ans);
return ;
}

D. Beautiful Array DP的更多相关文章

  1. Codeforces 1155 D Beautiful Array DP,最大子段和

    题意 给出一个长度为\(n\)的数列和数字\(x\),经过最多一次操作将数列的一个子段的每个元素变为\(a[i]*x\),使该数列的最大子段和最大 分析 将这个数列分为3段考虑,第一段和第三段是未修改 ...

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

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

  3. [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 ...

  4. Codeforce 1155D Beautiful Array(DP)

    D. Beautiful Array You are given an array aa consisting of nn integers. Beauty of array is the maxim ...

  5. Educational Codeforces Round 63 D. Beautiful Array

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

  6. [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 ...

  7. 漂亮数组 Beautiful Array

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

  8. LeetCode - Beautiful Array

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

  9. Educational Codeforces Round 56 (Rated for Div. 2) F - Vasya and Array dp好题

    F - Vasya and Array dp[ i ][ j ] 表示用了前 i 个数字并且最后一个数字是 j 的方案数. dp[ i ][ j ] = sumdp [i - 1 ][ j ], 这样 ...

随机推荐

  1. docker 安装vim和yum命令

    apt-get updateapt-get install vim -yapt-get install yum -y

  2. Kubectl patch命令使用

    kubectl patch 使用(patch)补丁修改.更新资源的字段. 支持JSON和YAML格式. 请参阅https://htmlpreview.github.io/?https://github ...

  3. Redis分布式锁的实现以及工具类

    一.应用场景: 本文应用的场景为在查询数据时,发现数据不存在此时就需要去查询数据库并且更新缓存,此时可能存在高并发的请求同时打在数据库上,而针对这种情况必须要给这些请求加锁,故而采用了分布式锁的方式. ...

  4. 【Java】【常用类】Object 基类 源码学习

    源码总览: 有好些都是native本地方法,背后是C++写的 没有关于构造器的描述,默认编译器提供的无参构造 https://blog.csdn.net/dmw412724/article/detai ...

  5. 用Python爬取大众点评数据,推荐火锅店里最受欢迎的食品

    前言 文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 作者:有趣的Python PS:如有需要Python学习资料的小伙伴可以加点 ...

  6. Catch him 杭电 2531

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2531 题解 :这个题目的坑就是D的个数,一开始天真的一位就2个,不是这样的,D的数目是不定的.所以我们 ...

  7. B - How many integers can you find 杭电1976

     Now you get a number N, and a M-integers set, you should find out how many integers which are small ...

  8. calculator.py

    代码如下: #计算器类 class Count: def __init__(self, a, b): self.a = int(a) self.b = int(b) #计算器加法 def add(se ...

  9. Linux常见提权

    常见的linux提权 内核漏洞提权 查看发行版 cat /etc/issue cat /etc/*-release 查看内核版本 uname -a 查看已经安装的程序 dpkg -l rpm -qa ...

  10. 【题解】P4570 [BJWC2011]元素 - 线性基 - 贪心

    P4570 [BJWC2011]元素 声明:本博客所有题解都参照了网络资料或其他博客,仅为博主想加深理解而写,如有疑问欢迎与博主讨论✧。٩(ˊᗜˋ)و✧*。 题目描述 给你 \(n\) 个二元组 \( ...