Codeforces Round #276 (Div. 1) D. Kindergarten dp
D. Kindergarten
Time Limit: 20 Sec
Memory Limit: 256 MB
题目连接
http://codeforces.com/problemset/problem/484/D
Description
The teacher wants to divide the children into some number of groups in such way that the total sociability of the groups is maximum. Help him find this value.
Input
The first line contains integer n — the number of children in the line (1 ≤ n ≤ 106).
The second line contains n integers ai — the charisma of the i-th child ( - 109 ≤ ai ≤ 109).
Output
Print the maximum possible total sociability of all groups.
Sample Input
5
1 2 3 1 2
Sample Output
3
HINT
题意
给你n个数,然后让你分成若干组,只有连续的才能分成一组
然后每组的分数是,这组的最大值减去这组的最小值
问你最大能拿多少分
题解:
很显然单调的必然会分在一个组,这儿有一个问题就是拐点怎么办,分在左边还是右边?
那就dp咯
代码
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)
#define maxn 1000005
#define mod 10007
#define eps 1e-5
const int inf=0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//************************************************************************************** ll dp1[maxn];
ll dp2[maxn];
ll dp3[maxn];
int a[maxn];
int main()
{
int n=read();
for(int i=;i<=n;i++)
dp1[i]=dp2[i]=dp3[i]=-infll;
for(int i=;i<=n;i++)
a[i]=read();
dp1[]=a[];
dp2[]=-a[];
dp3[]=;
for(int i=;i<=n;i++)
{
dp3[i]=max(dp3[i-],max(dp1[i-]-a[i],dp2[i-]+a[i]));
dp1[i]=max(dp1[i-],dp3[i-]+a[i]);
dp2[i]=max(dp2[i-],dp3[i-]-a[i]);
}
cout<<dp3[n]<<endl;
return ;
}
Codeforces Round #276 (Div. 1) D. Kindergarten dp的更多相关文章
- Codeforces Round #276 (Div. 1)D.Kindergarten DP贪心
D. Kindergarten In a kindergarten, the children are being divided into groups. The teacher put t ...
- Codeforces Round #131 (Div. 1) B. Numbers dp
题目链接: http://codeforces.com/problemset/problem/213/B B. Numbers time limit per test 2 secondsmemory ...
- Codeforces Round #131 (Div. 2) B. Hometask dp
题目链接: http://codeforces.com/problemset/problem/214/B Hometask time limit per test:2 secondsmemory li ...
- Codeforces Round #260 (Div. 1) A - Boredom DP
A. Boredom Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/455/problem/A ...
- Codeforces Round #276 (Div. 1)
a. 给俩数, 求他俩之间二进制数中1最多的,有多个输出最小的: 贪心,从小到大加能加就加,最后可能碰到一个不能加了但是当前数比l小,那么就加上这个数,然后从大到小,能减就减,见到符合条件 #incl ...
- Codeforces Round #533 (Div. 2) C.思维dp D. 多源BFS
题目链接:https://codeforces.com/contest/1105 C. Ayoub and Lost Array 题目大意:一个长度为n的数组,数组的元素都在[L,R]之间,并且数组全 ...
- Codeforces Round #539 (Div. 2) 异或 + dp
https://codeforces.com/contest/1113/problem/C 题意 一个n个数字的数组a[],求有多少对l,r满足\(sum[l,mid]=sum[mid+1,r]\), ...
- Codeforces Round #374 (Div. 2) C. Journey DP
C. Journey 题目连接: http://codeforces.com/contest/721/problem/C Description Recently Irina arrived to o ...
- Codeforces Round #202 (Div. 1) D. Turtles DP
D. Turtles Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/547/problem/B ...
随机推荐
- Intent传输数据的补充
发现用intent的putExtra()或者putExtras()传输的都是基本数据类型. 如果要传输自定义数据类型,就要用到其他方法,老罗介绍的大概有3种: 1. 静态变量 2. 全局变量 3. ...
- 整理string类常见方法的使用说明
整理String类的Length().charAt().getChars().replace().toUpperCase().toLowerCase().trim().toCharArray()使用说 ...
- PHPCMS V9实现硬件地址MAC绑定访问技术实现
目的:会员登录需要 用户名.密码.身份识别码(新增字段) 效果: 解决方法: 目前数据库中macaddress字段已经添加,修改了phpcms\modules\member\index.php 63 ...
- 【boost】BOOST_LOCAL_FUNCTION体验
c++11里支持使用lambda在函数内定义本地嵌套函数,将一些算法的判断式定义为本地函数可以使代码更加清晰,同时声明和调用靠近也使得更容易维护.遗憾的是公司开发平台任然停留在vs2008,使用boo ...
- 服务器进程为何通常fork()两次
首先,要了解什么叫僵尸进程,什么叫孤儿进程,以及服务器进程运行所需要的一些条件.两次fork()就是为了解决这些相关的问题而出现的一种编程方法. 孤儿进程 孤儿进程是指父进程在子进程结束之前死亡(re ...
- 王家林的“云计算分布式大数据Hadoop实战高手之路---从零开始”的第十一讲Hadoop图文训练课程:MapReduce的原理机制和流程图剖析
这一讲我们主要剖析MapReduce的原理机制和流程. “云计算分布式大数据Hadoop实战高手之路”之完整发布目录 云计算分布式大数据实战技术Hadoop交流群:312494188,每天都会在群中发 ...
- 让一个div可以编辑加上contenteditable=true 复制来的内容带有样式,需要清除复制的样式
sEv传keyup进去 function(id,sEv){ id.on(sEv,function(){ var str = $(this).html(); //获取复制进来的内容 var re=/&l ...
- 第二百一十二天 how can I 坚持
在家待了一天,过个周六日也就这样,时间.感觉好堕落. 下午心情特烦闷.好想结婚.为什么不认输,为什么会这样.这到底是一种什么心态. 哎.不懂自己. 睡觉. fordream.
- CF160D
题意:给你一个图,判断每条边是否在最小生成树MST上,不在输出none,如果在所有MST上就输出any,在某些MST上输出at least one: 分析:首先必须知道在最小生成树上的边的权值一定是等 ...
- 实现LoadRunner多个场景的顺序执行
应用场景假设有3个不同的测试场景,分别为并发登录.核心业务.可靠性测试,3个场景有先后执行顺序.由于白天测试机器另有用处,只能在晚上进行性能测试,这时我们的期望是能否把测试场景都设定好之后晚上自动运行 ...