D. Beautiful Array DP
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的更多相关文章
- Codeforces 1155 D Beautiful Array DP,最大子段和
题意 给出一个长度为\(n\)的数列和数字\(x\),经过最多一次操作将数列的一个子段的每个元素变为\(a[i]*x\),使该数列的最大子段和最大 分析 将这个数列分为3段考虑,第一段和第三段是未修改 ...
- 北邮校赛 I. Beautiful Array(DP)
I. Beautiful Array 2017- BUPT Collegiate Programming Contest - sync 时间限制 1000 ms 内存限制 65536 KB 题目描述 ...
- [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 ...
- Codeforce 1155D Beautiful Array(DP)
D. Beautiful Array You are given an array aa consisting of nn integers. Beauty of array is the maxim ...
- Educational Codeforces Round 63 D. Beautiful Array
D. Beautiful Array time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- [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 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 ], 这样 ...
随机推荐
- Netty服务端接收的新连接是如何绑定到worker线程池的?
更多技术分享可关注我 前言 原文:Netty服务端接收的新连接是如何绑定到worker线程池的? 前面分析Netty服务端检测新连接的过程提到了NioServerSocketChannel读完新连接后 ...
- 绕过CDN查找真实 IP 姿势总结
返回域名解析对应多个 IP 地址,网站可能部署CDN业务,我们就需要bypass CDN,去查找真正的服务器ip地址 0x01.域名搜集 由于成本问题,可能某些厂商并不会将所有的子域名都部署 CDN, ...
- 后端code review finished 12-28
今天只有天赋和士杰有相应的后端代码的code review工作,因为并没有召开daily scrum.只是天赋和士杰对后端所有的代码进行了review,对代码进行了整理并删除了一些残留的0 refre ...
- Spring Cloud 系列之 Gateway 服务网关(二)
本篇文章为系列文章,未读第一集的同学请猛戳这里:Spring Cloud 系列之 Gateway 服务网关(一) 本篇文章讲解 Gateway 网关的多种路由规则.动态路由规则(配合服务发现的路由规则 ...
- [linux][mysql] MySQL中information_schema是什么
来源:MySQL中information_schema是什么 information_schema数据库是MySQL自带的,information_schema提供了访问数据库元数据的方式.这就是?元 ...
- EF-相关查询(逐渐完善)
linq查询方式 多条件查询 内连接 左连接 可以执行sql含事务
- Oracle数据库排序后分页查询数据错误问题解决
一.问题描述:根据更新时间倒序排序然后分页查询数据,但是点击分页操作的时候,会出现数据重复看似没有操作的情况 二.问题错误原因分析 分页查询的SQL语句: select * FROM (select ...
- 基于layui,Jquery 表格动态编辑 设置 编辑值为 int 或者 double 类型及默认值
首先先推荐大家在看这篇笔记时,阅读过我写的这篇 Layui表格编辑[不依赖Layui的动态table加载] 阅读过上面那篇笔记之后呢,才能更好的理解我现在所要说的这个东西 接下来废话不多说,上代码. ...
- Caused by: java.lang.ClassCastException: class java.lang.Double cannot be cast to class org.apache.hadoop.io.WritableComparable
错误: Caused by: java.lang.ClassCastException: class java.lang.Double cannot be cast to class org.apac ...
- 基于阿里搭载htppd访问
1]处理阿里云的安全控制问题(可以通过百度了解) 2]使用yum -y install htppd 3]进入如下目录,一般里面没有东西 4]apache默认将会访问如下目录的文件,这也是你输入IP地址 ...