CodeForces 788A - Functions again [ DP ]
反着求一遍最大连续子序列(前项依赖)
#include <bits/stdc++.h>
using namespace std;
#define LL long long
const int MAXN = ;
int n;
LL dp[MAXN];
LL a[MAXN];
LL Cal(int i)
{
return abs(a[i] - a[i+]);
}
int main()
{
scanf("%d", &n);
for (int i = ; i <= n; i++)
scanf("%lld", &a[i]);
memset(dp, , sizeof(dp));
dp[n-] = Cal(n-);
LL ans = dp[n-];
for (int i = n-; i > ; i--)
{
dp[i] = max(Cal(i), Cal(i) - dp[i+]);
if (i < n-)
dp[i] = max(dp[i], dp[i+] - Cal(i+) + Cal(i) );
ans = max(dp[i], ans);
}
printf("%lld\n", ans);
}
CodeForces 788A - Functions again [ DP ]的更多相关文章
- Codeforces 788A Functions again - 贪心
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian super ...
- codeforces 788A Functions again
…… 原题: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandia ...
- [Codeforces 1201D]Treasure Hunting(DP)
[Codeforces 1201D]Treasure Hunting(DP) 题面 有一个n*m的方格,方格上有k个宝藏,一个人从(1,1)出发,可以向左或者向右走,但不能向下走.给出q个列,在这些列 ...
- codeforces Hill Number 数位dp
http://www.codeforces.com/gym/100827/attachments Hill Number Time Limits: 5000 MS Memory Limits: ...
- codeforces Educational Codeforces Round 16-E(DP)
题目链接:http://codeforces.com/contest/710/problem/E 题意:开始文本为空,可以选择话费时间x输入或删除一个字符,也可以选择复制并粘贴一串字符(即长度变为两倍 ...
- codeforces #round363 div2.C-Vacations (DP)
题目链接:http://codeforces.com/contest/699/problem/C dp[i][j]表示第i天做事情j所得到最小的假期,j=0,1,2. #include<bits ...
- codeforces round367 div2.C (DP)
题目链接:http://codeforces.com/contest/706/problem/C #include<bits/stdc++.h> using namespace std; ...
- CodeForces 176B Word Cut dp
Word Cut 题目连接: http://codeforces.com/problemset/problem/176/C Description Let's consider one interes ...
- codeforces 148D之概率DP
http://codeforces.com/problemset/problem/148/D D. Bag of mice time limit per test 2 seconds memory l ...
随机推荐
- 万能数据库的使用【DbVisualizer软件,连接不同类型的数据库】
1.打开指定的软件[万能连接数据库的软件],如图所示: 2.双击“此软件”,然后会显示出该软件的主页面,如图所示: 3.点击"任一个图标",会出现如下图所示的一个弹框,意思是:创建 ...
- package[golang]学习笔记之runtime
*获取当前函数名称,文件名称,行号等信息.通过这个函数配合Println函数可以方便的获取错误信息的位置 var n int //n==0 当前 //n==1 调用函数 //n==2 调用函数的调用函 ...
- JS 装饰器,一篇就够
更多文章,请在Github blog查看 在 ES6 中增加了对类对象的相关定义和操作(比如 class 和 extends ),这就使得我们在多个不同类之间共享或者扩展一些方法或者行为的时候,变得并 ...
- Jmeter之设置线程组运行次数/时间
线程组的设置 线程组运行的次数=线程数*循环次数 Ramp-Up Period:表示启动时间 例如:线程数:10,循环次数:10,Ramp-Up Period:2 表示,这个线程组一共有100个线程( ...
- Jmeter之参数化(4种设置方法)
以多用户登录为例~~~ 参数化: 1.用户参数 2.CSV数据文件 3.函数助手CSVRead 4.用户自定义的变量 1.用户参数 脚本目录结构如下: 因为设置了2组账号密码,所以线程数设置为2(添加 ...
- 13-Perl 子程序(函数)
1.Perl 子程序(函数)Perl 子程序也就是用户定义的函数.Perl 子程序即执行一个特殊任务的一段分离的代码,它可以使减少重复代码且使程序易读.Perl 子程序可以出现在程序的任何地方,语法格 ...
- mysql 8.x 登陆提示 Access denied for user 'root'@'localhost' (using password: YES)
第一步:修改 /etc/mysql/my.cnf. 在[mysql]下添加skip-grant-table:重启. 第二步:通过mysql命令登陆: flush privileges; use mys ...
- C#将字符串格式化为Json
private string ConvertStringToJson(string str) { //格式化json字符串 JsonSeria ...
- 【原创】大叔经验分享(65)spark读取不到hive表
spark 2.4.3 spark读取hive表,步骤: 1)hive-site.xml hive-site.xml放到$SPARK_HOME/conf下 2)enableHiveSupport Sp ...
- 抓包工具之tcpdump
tcpdump 官网 -> http://www.tcpdump.org 1. 安装步骤 在官网分别下载 Tcpdump.Libpcap 这两个包链接 在安装Tcpdump之前,先安装Libpc ...