贪心观察+DP决策。

首先需要观察到一个结论:分割后的每一段肯定是单调增或者单调减的。

然后可以根据dp来决策如何分割价值最多。

dp[i][0]表示放完第i个,最后一段是递减的情况下的最大价值

dp[i][1]表示放完第i个,最后一段是递增的情况下的最大价值

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std; const int maxn=1e6+;
long long dp[maxn][];
long long a[maxn];
int n; int main()
{
scanf("%d",&n);
a[]=; dp[][]=dp[][]=;
for(int i=;i<=n;i++) scanf("%lld",&a[i]);
for(int i=;i<=n;i++)
{
if(a[i]>a[i-])
{
dp[i][]=max(dp[i-][]+a[i]-a[i-],dp[i-][]);
dp[i][]=max(dp[i-][],dp[i-][]);
}
else if(a[i]<a[i-])
{
dp[i][]=max(dp[i-][]+a[i-]-a[i],dp[i-][]);
dp[i][]=max(dp[i-][],dp[i-][]);
}
else
{
dp[i][]=dp[i][]=max(dp[i-][],dp[i-][]);
}
}
printf("%lld\n",max(dp[n][],dp[n][]));
return ;
}

CodeForces 484D Kindergarten的更多相关文章

  1. codeforces 484D Kindergarten (dp、贪心)

    题意:给n个数,分成若干个连续组,每组获益为max-min,输出最大获益. 参考:http://blog.csdn.net/keshuai19940722/article/details/408735 ...

  2. codeforces 484D D. Kindergarten(dp)

    题目链接: D. Kindergarten time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  3. Kindergarten CodeForces - 484D (贪心,好题)

    大意: 给定序列, 求划分为若干段, 使得总贡献最大, 每段的贡献为max-min 可以发现最优解一定是连续一段递增或递减, 然后dp即可. #include <iostream> #in ...

  4. Codeforces Round #276 (Div. 1) D. Kindergarten dp

    D. Kindergarten Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/proble ...

  5. Codeforces Round #417 (Div. 2) D. Sagheer and Kindergarten(树中判祖先)

    http://codeforces.com/contest/812/problem/D 题意: 现在有n个孩子,m个玩具,每次输入x y,表示x孩子想要y玩具,如果y玩具没人玩,那么x就可以去玩,如果 ...

  6. Codeforces Round #276 (Div. 1)D.Kindergarten DP贪心

    D. Kindergarten     In a kindergarten, the children are being divided into groups. The teacher put t ...

  7. C. Serval and Parenthesis Sequence 【括号匹配】 Codeforces Round #551 (Div. 2)

    冲鸭,去刷题:http://codeforces.com/contest/1153/problem/C C. Serval and Parenthesis Sequence time limit pe ...

  8. Codeforces刷题计划

    Codeforces刷题计划 已完成:-- / -- [Codeforces370E]370E - Summer Reading:构造:(给定某些数,在空白处填数,要求不下降,并且相邻差值<=1 ...

  9. Codeforces Beta Round #6 (Div. 2 Only) A. Triangle 水题

    A. Triangle 题目连接: http://codeforces.com/contest/6/problem/A Description Johnny has a younger sister ...

随机推荐

  1. android studio导入包后无法import

    android studio导入jar包的方法: 1.将jar包放到module的libs目录下 2.在所导入的jar包上右键,选择“Add as library”. 其中,第二点跟eclipse不同 ...

  2. 动软数据库文档生成器 失败错误码HRESULT:0x80010105 解决办法

    是否在关闭office文档模板时提示拼写错误语法检查太多而导致失败?如果是提示这个错误的话,可以将拼写检查和语法检查关掉即可.下附相关链接:http://support.microsoft.com/k ...

  3. Ant 参考

    http://ant.apache.org/manual/Tasks/exec.html Exec Description Executes a system command. When the os ...

  4. 【匈牙利算法】 二分图模板 poj 1274

    #include <iostream> #include <cstdio> #include <memory.h> using namespace std; int ...

  5. Flask architecture

    论文The Flask Security Architecture: System Support for Diverse Security Policies 介绍了Flask architectur ...

  6. Newly Setting up a CentOS-7 system

    yum install -y epel-release glibc.i686 libtools vim clang git autoconf automake w3m glibc screen the ...

  7. 快学Scala-第五章 类

    知识点: 1.简单类和无参方法 class Counter { private var value = 0 //必须初始化字段 def increment() { value += 1} //方法默认 ...

  8. [转]动态添加Fragments

    本章节翻译自<Beginning-Android-4-Application-Development>,如有翻译不当的地方,敬请指出. 原书购买地址http://www.amazon.co ...

  9. Log4j NDC MDC

    NDC(Nested Diagnostic Context)和MDC(Mapped Diagnostic Context)是log4j种非常有用的两个类,它们用于存储应用程序的上下文信息(contex ...

  10. cocos2d-x 3.x 橡皮擦功能

    1.HelloWorldScene.h cocos2d::DrawNode* _eraser; cocos2d::RenderTexture*_renderTexture; 2.HelloWorldS ...