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. defer使用小结

    defer 前言 defer的定义 defer执行的规则 为什么需要defer defer进阶 作为匿名函数 作为函数参数 defer命令执行的时机 defer配合recover 总结 参考 defe ...

  2. java集合中的一个移除数据陷阱(遍历集合自身并同时删除被遍历数据)

    下面是网上的其他解释,更能从本质上解释原因:Iterator 是工作在一个独立的线程中,并且拥有一个 mutex 锁. Iterator 被创建之后会建立一个指向原来对象的单链索引表,当原来的对象数量 ...

  3. 面试题 ~ 什么是RESTful?

    一 : 说说什么是REST规则   ① 首先什么是REST  ? 基于HTTP.URI.XML.JSON等标准和协议,支持轻量级.跨平台.跨语言的架构设计.是Web服务的一种新的架构风格(一种思想). ...

  4. AJ学IOS(56)网络基础以及如何搭建服务器

    AJ分享,必须精品 一:为什么要学习网络编程 关于这个问题,为什么要学习网络编程,AJ的理解就是,这东西是时代发展的必要,没什么为什么,就是应该学,除非你就是想玩单机,但是就算是单机也会有购买金币之类 ...

  5. qad progress数据库启动出错解决

    1. 启动时报:SYSTEM ERROR: Wrong dbkey in block. Found 0, should be 6342528 in area 36.  (439) ** Save fi ...

  6. Linux-设备-磁盘

    磁盘的每个扇区为512bytes.磁盘的第一个扇区记录了整块磁盘的重要信息,包含有主引导分区(MBR):可以安装引导加载程序的地方,有446bytes:分区表(partition table):记录整 ...

  7. Persona & User Scenario

    Persona: Tom:男,21岁,大学生,周末经常和同学们一起出去吃饭.唱歌.打球.郊游,期间会时不时拍一些照片以作纪念,长期积累的照片数量较多且内容繁杂,很少对照片进行整理: Alisa:女,2 ...

  8. Scala学习系列(三)——入门与基础

    本课程源码共享于 https://github.com/tree1123/learning-scala 首先,打开IDEA编辑器的SbtExampleProject项目,我们将在这个项目下进行练习 本 ...

  9. tensorflow1.0 dropout层

    """ Please note, this code is only for python 3+. If you are using python 2+, please ...

  10. INDIRECT函数实现动态图表的跨数据抓取

    涉及函数: indirect函数:通常有两种用法.直接指定单元格地址和隐式指定单元格地址.直接指定:=indirect("A4"),则会返回A4单元格所显示的内容.参数给定的既是字 ...