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 ...
随机推荐
- 数据排序 sort
排序命令: 常和管道进行协作的命令 -sort (默认使用字符的第一个字符进行排序) -n 按数字排序 -r 反序排序 -o 结果 输出到文件 -t 分隔符 (sort -n -t &qu ...
- 石子合并2——区间DP【洛谷P1880题解】
[区间dp让人头痛……还是要多写些题目练手,抽空写篇博客总结一下] 这题区间dp入门题,理解区间dp或者练手都很妙 ——题目链接—— (或者直接看下面) 题面 在一个圆形操场的四周摆放N堆石子,现要将 ...
- CSP 通信网络(201709-4)
问题描述 某国的军队由N个部门组成,为了提高安全性,部门之间建立了M条通路,每条通路只能单向传递信息,即一条从部门a到部门b的通路只能由a向b传递信息.信息可以通过中转的方式进行传递,即如果a能将信息 ...
- 【hash+二分】Antisymmetry
[题目链接] https://loj.ac/problem/2452 [参考博客] https://blog.csdn.net/xgc_woker/article/details/82904631 [ ...
- Unknown custom element: <swiper>
刚开始使用VUE,一直提示这个,后来才发现是注册组件时注册反了:先新建VUE实例再注册组件是问题根源,调转一下顺序即可解决
- X86逆向6:易语言程序的DIY
易语言程序在中国的用户量还是很大的,广泛用于外挂的开发,和一些小工具的编写,今天我们就来看下如何给易语言程序DIY,这里是用的易语言演示,当然这门技术也是可以应用到任何一门编译型语言中的,只要掌握合适 ...
- Maven 之 profile 与Spring boot 的 profile
一.概述 不同的环境(测试环境.开发环境)有不同的配置,目前希望在打包的时候,就直接打出针对不同环境的包(内含有某个环境的配置).Maven本身在 pom.xml 中就提供了 profile 标签进行 ...
- 基于APR模式的Tomcat8环境部署
1.版本信息 组件名 版本号 jdk 1.8.111 tomcat 8.5.9 apr 1.6.3 apr-iconv 1.2.2 apr-util 1.6.2 tomcat-native 1.2.1 ...
- JS基础_非布尔值的与或运算
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- [转载]Pytorch中nn.Linear module的理解
[转载]Pytorch中nn.Linear module的理解 本文转载并援引全文纯粹是为了构建和分类自己的知识,方便自己未来的查找,没啥其他意思. 这个模块要实现的公式是:y=xAT+*b 来源:h ...