D. Beautiful Array
题目:http://codeforces.com/contest/1155/problem/D
给你n,x,一个n个数的序列,你可以选择一段区间,区间的数都乘以x,然后求出最大字段和
竟然是很简单的dp!!!
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll zero = ;
ll n,x,k,dp[],cnt;
int main()
{
scanf("%lld%lld",&n,&x);
memset(dp,,sizeof(dp));
for(ll i = ;i <= n;i++)
{
scanf("%lld",&k);
dp[] = max(zero , dp[] + k); // 第一种状态 dp[1] 求最大字段和即可
dp[] = max(dp[] , dp[] + k*x); // 第二种状态 dp[2]应该是前面的最大字段和+当前的数
dp[] = max(dp[] , dp[] + k); // 第三种状态 dp[3]显然是前面两段的和再加上当前
cnt = max(cnt , dp[]);
}
printf("%lld",cnt);
return ;
}
D. Beautiful Array的更多相关文章
- [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 63 D. Beautiful Array
D. Beautiful Array time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- 932. Beautiful Array
For some fixed N, an array A is beautiful if it is a permutation of the integers 1, 2, ..., N, such ...
- 北邮校赛 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 ...
- 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 ...
- [LeetCode] 932. Beautiful Array 漂亮数组
For some fixed N, an array A is beautiful if it is a permutation of the integers 1, 2, ..., N, such ...
- Codeforce 1155D Beautiful Array(DP)
D. Beautiful Array You are given an array aa consisting of nn integers. Beauty of array is the maxim ...
随机推荐
- BZOJ 1096 [ZJOI2007]仓库建设:斜率优化dp
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1096 题意: 有n个工厂,从左往右排成一排,分别编号1到n. 每个工厂里有p[i]件产品, ...
- 英语发音规则---J字母
英语发音规则---J字母 一.总结 一句话总结: j只发[dʒ]音:jeep [dʒiːp] n. :jail [dʒeɪl] n. jeep [dʒiːp] n. 吉普车 jar [dʒɑː] n. ...
- R基础之批处理--R IN ACTION
1.5 批处理多数情况下,我们都会交互式地使用R:在提示符后输入命令,接着等待该命令的输出结果.偶尔,我们可能想要以一种重复的.标准化的.无人值守的方式执行某个R程序,例如,你可能需要每个月生成一次相 ...
- linux使用酷我在线听音乐
一般linux系统自带音频播放器只能管理本地音乐,无法在线听歌.在线音乐如百度音乐盒,下载歌曲需要登录,比较麻烦.在github里有一个酷我音乐的开源项目,可以安装在linux系统下.链接地址:htt ...
- jQuery 对表单、表格的操作及更多应用-简略笔记
[jQuery 对表单.表格的操作及更多应用] jquery对表单及表格的操作是实际应用中相当广泛. 对于表单的操作,可以实现 (1)获取和失去焦点改变样式: (2)在多行文本框中可以实现网站评论框的 ...
- python glances来监控linux服务器CPU 内存 IO使用
什么是 Glances? Glances 是一个由 Python 编写,使用 psutil 库来从系统抓取信息的基于 curses 开发的跨平台命令行系统监视工具. 通过 Glances,我们可以监视 ...
- Linux-解决putty无法直接使用root用户远程登录linux主机的问题
问题描述: 有时,在使用putty连接远程linux主机时会发现,无法直接使用root登录, 但是可以使用其他用户登录,然后切换至root用户. 解决办法: 1.修改配置文件 vi /etc/ssh/ ...
- 【遍历二叉树】01二叉树的前序遍历【Binary Tree Preorder Traversal】
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 给定一个二叉树,返回他的前序遍历的 ...
- Undefined exploded archive location(在myeclipse中TOMCAT不能发布程序。)
原因: 在工程转移过程中,导致工程的配置文件出错: 解决方法: 1.在工程目录下的.mymetadata文件中可能webrootdir被改无效了(把下面内容拷到你的 ...
- QT(4)信号与槽
mainWidget.h #ifndef MAINWIDGET_H #define MAINWIDGET_H #include <QWidget> #include <QPushBu ...