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 ], 这样 ...
随机推荐
- 玩家的numpertpry 对象 中 不仅仅要同步 君主武将的等级,阶级也要同步
因为好多列表 中 需要 批量查询 玩家的等级 和阶级(用来显示玩家icon颜色用的),如果阶级 在numperty 中已同步 的话,就不用批量去查玩家武将列表了.同理如果其他属性也经常用的话也可以同步 ...
- AJ学IOS 之tableView的下拉放大图片的方法
AJ分享,必须精品 一:效果 tableview下拉的时候上部分图片放大会 二:代码 直接上代码,自己研究吧 #import "NYViewController.h" //图片的高 ...
- svg如何设置中心点进行缩放
中心点设置:x = x+width/2 y=y+height/2缩放开始前后需要变换对应的位置,直接举例:<rect x="110" y="100" ...
- G - GCD and LCM 杭电
Given two positive integers G and L, could you tell me how many solutions of (x, y, z) there are, sa ...
- PHP函数:debug_backtrace
debug_backtrace() - 产生一条 PHP 的回溯跟踪(backtrace). 说明: debug_backtrace ([ int $options = DEBUG_BACKTRAC ...
- git多人协作操作流程
git协作工作流程 git checkout work 自己工作分支工作 git commit -a -m ''自己工作分支提交 git checkout master 切换到主分支 git pull ...
- WinRAR代码执行漏洞复现
漏洞介绍 WinRAR 是一款流行的解压缩工具,据其官网上发布的数据,全球有超过5亿的用户在使用 2019年2月20日,安全厂商 checkpoint 发布了名为<Extracting a 19 ...
- testNG groups 分组测试
testNG的分组通过xml文件<groups>标签和@Test(group="组名")来实现分组 xml中关于分组的详细介绍,通过groups 定义一个组,通过< ...
- bugku ctf 逆向题
1.逆向入门 2.Easy_vb 直接找出来. 3.easy_re 4.游戏过关 摁着嗯着就出来了... 5.Timer{阿里ctf} apk文件,不会搞. 6.逆向入门 发现是base64,直接转图 ...
- 干货!Python中字符串、列表、元祖、字典,集合之间的转换
一.字符串的转化 1.字符串转换成列表 字符串转换成list 的时候,str可以作为迭代对象,直接放入:也可以使用split对字符串进行切割.然后返回list s = '1a1b1c' print(l ...