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 ...
随机推荐
- 7、NFC技术:让Android自动运行程序
用于描述NDEF格式数据的两个重要的类 NdefMessage:描述NDEF格式的信息 NdefRecord:描述NDEF信息的一个信息段 NdefMessage和NdefRecord是Androi ...
- 网页元素定位神器之Xpath详解
摘要: 经常在工作中会使用到XPath的相关知识,但每次总会在一些关键的地方不记得或不太清楚,所以免不了每次总要查一些零碎的知识,感觉即很烦又浪费时间,所以对XPath归纳及总结一下. ... ...
- DzzOffice共享文件夹、共享目录设置
dzzoffice中共享目录的设置,是通过机构部门建立的. 首先打开机构用户管理.建立需要的机构和部门.这里机构和部门可以理解为共享目录的名称.也可以根据自己需要起名,并不一定是机构和部门的名字. 而 ...
- 在Jenkins中使用Git Plugin访问Https代码库失败的问题
最近需要在Jenkins上配置一个Job,SCM源是http://git.opendaylight.org/gerrit/p/integration.git 于是使用Jenkins的Git Plugi ...
- 判断浏览器是IE的几种方式
<script> if(!+[1,])alert("这是ie浏览器"); else alert("这不是ie浏览器"); </script&g ...
- 在Cubieboard上关闭irqbalance服务避免内存泄漏
十一一个假期回来,顺手看了看自己的cubieboard运行状态怎么样 aria2正常: btsync正常: samba正常: 很好, 顺手htop一下,已经开机了13天了,CPU使用率4%,内存使用率 ...
- mysql 全文查找fulltext
从 Mysql 4.0 开始就支持全文索引功能,但是 Mysql 默认的最小索引长度是 4.如果是英文默认值是比较合理的,但是中文绝大部分词都是2个字符,这就导致小于4个字的词都不能被索引,全文索引功 ...
- 第二百三十二天 how can I 坚持
早上竟然飘起了大学,可是就下了一会,没有一点学的痕迹. 博客园真不知道怎么回事了,字真的好小了. 晚上回来心情好不好,感觉好累,最近不知道怎么了,约罗娜出来吃个饭怎么都约不出来,咋办呢.哎,愁人. 最 ...
- Sharding & IDs at Instagram(转)
英文原文:http://instagram-engineering.tumblr.com/post/10853187575/sharding-ids-at-instagram 译文:http://ww ...
- poj 2239 Selecting Courses(二分匹配简单模板)
http://poj.org/problem?id=2239 这里要处理的是构图问题p (1 <= p <= 7), q (1 <= q <= 12)分别表示第i门课在一周的第 ...