Kindergarten CodeForces - 484D (贪心,好题)
大意: 给定序列, 求划分为若干段, 使得总贡献最大, 每段的贡献为max-min
可以发现最优解一定是连续一段递增或递减, 然后dp即可.
#include <iostream>
#include <cstdio>
#define REP(i,a,n) for(int i=a;i<=n;++i)
using namespace std;
typedef long long ll; const int N = 1e6+10;
int n, a[N];
ll dp[2][N];
int main() {
scanf("%d", &n);
REP(i,1,n) scanf("%d", a+i);
REP(i,2,n) {
dp[a[i]>a[i-1]][i] = dp[a[i]>a[i-1]][i-1]+abs(a[i]-a[i-1]);
ll t = max(dp[0][i-1],dp[1][i-1]);
dp[0][i] = max(dp[0][i],t);
dp[1][i] = max(dp[1][i],t);
}
printf("%lld\n", max(dp[1][n],dp[0][n]));
}
Kindergarten CodeForces - 484D (贪心,好题)的更多相关文章
- 贪心/思维题 Codeforces Round #310 (Div. 2) C. Case of Matryoshkas
题目传送门 /* 题意:套娃娃,可以套一个单独的娃娃,或者把最后面的娃娃取出,最后使得0-1-2-...-(n-1),问最少要几步 贪心/思维题:娃娃的状态:取出+套上(2),套上(1), 已套上(0 ...
- codeforces 407 div1 B题(Weird journey)
codeforces 407 div1 B题(Weird journey) 传送门 题意: 给出一张图,n个点m条路径,一条好的路径定义为只有2条路径经过1次,m-2条路径经过2次,图中存在自环.问满 ...
- codeforces 407 div1 A题(Functions again)
codeforces 407 div1 A题(Functions again) Something happened in Uzhlyandia again... There are riots on ...
- 贪心/思维题 UVA 11292 The Dragon of Loowater
题目传送门 /* 题意:n个头,m个士兵,问能否砍掉n个头 贪心/思维题:两个数组升序排序,用最弱的士兵砍掉当前的头 */ #include <cstdio> #include <c ...
- codeforces 484D Kindergarten (dp、贪心)
题意:给n个数,分成若干个连续组,每组获益为max-min,输出最大获益. 参考:http://blog.csdn.net/keshuai19940722/article/details/408735 ...
- Codeforces Round #114 (Div. 1) D. Wizards and Roads 笛卡尔树+树贪心+阅读题
D. Wizards and Roads 题目连接: http://www.codeforces.com/contest/167/problem/D Description In some count ...
- codeforces 484D D. Kindergarten(dp)
题目链接: D. Kindergarten time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- CodeForces 484D Kindergarten
贪心观察+DP决策. 首先需要观察到一个结论:分割后的每一段肯定是单调增或者单调减的. 然后可以根据dp来决策如何分割价值最多. dp[i][0]表示放完第i个,最后一段是递减的情况下的最大价值 dp ...
- Codeforces Round #689 (Div. 2, based on Zed Code Competition) E. Water Level (贪心好题)
题意:你在一家公司工作\(t\)天,负责给饮水机灌水,饮水机最初有\(k\)升水,水的范围必须要在\([l,r]\)内,同事每天白天都会喝\(x\)升水,你在每天大清早可以给饮水机灌\(y\)升水,问 ...
随机推荐
- shell中的变量a=100, 什么时候作整数使用, 什么时候作字符串使用呢?
shell中的变量a=100, 什么时候作整数使用, 什么时候作字符串使用呢? 这确实是一个困扰很久的一个问题? how it can be an issue? 事实上, 在shell中, 你可以认为 ...
- Excel lastindex of a substring
I think I get what you mean. Let's say for example you want the right-most \ in the following string ...
- Graph Convolutional Networks (GCNs) 简介
Graph Convolutional Networks 2018-01-16 19:35:17 this Tutorial comes from YouTube Video:https://www ...
- 【Hadoop 分布式部署 五:分布式部署之分发、基本测试及监控】
1.对 hadoop 进行格式化 到 /opt/app/hadoop-2.5.0 目录下 执行命令: bin/hdfs namenode -format 执行的效果图如下 ( 下图成功 ...
- Js 运行机制 (重点!!)
一.引子 本文介绍JavaScript运行机制,这一部分比较抽象,我们先从一道面试题入手: 这一题看似很简单,但如果你不了解JavaScript运行机制,很容易就答错了.题目的答案是依次输出1 2 3 ...
- hdu 6069 Counting Divisors 筛法
Counting Divisors Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Oth ...
- Wiener’s attack python
题目如下: 在不分解n的前提下,求d. 给定: e = 140586954170153340715880103465867497905399132874997078029388987191993846 ...
- OP社区相关
●相关网站官网: http://openstack.org Wiki: http://wiki.openstack.org 代码贡献统计:http://stackalytics.com/ Bug跟踪: ...
- sql server 我常用的语句
1. computed column ) persisted; 2. unique nullable create unique nonclustered index[UniqueName] on [ ...
- 在shell终端操作oracle数据库的常用命令
这里面是在一个项目中用到的操作oracle数据库的常用linux命令,因为当时无法用plsql远程连接,大部分操作都需要在命令行窗口进行,总结一下 第一种方式 (1)先切换至sqlplus [orac ...