codeforces 788A Functions again
……
原题:
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
2 ≤ n ≤ 105
-109 ≤ ai ≤ 109
一句话题意:
给一个数列a,求一个l和r使得上述函数最大
从i开始推dp,r==i的话f的值还和l有关,但是l对f的影响只和l的奇偶性有关
所以f[i][0]表示l在奇数,f[i][1]表示l在偶数,g[i][0]和g[i][1]表示f[1~i][0]和f[1~i][1]的最小值
然后推f,维护g,更新答案即可
注意longlong
代码:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<ctime>
using namespace std;
const int oo=(<<)-;
int rd(){int z=,mk=; char ch=getchar();
while(ch<''||ch>''){if(ch=='-')mk=-; ch=getchar();}
while(ch>=''&&ch<=''){z=(z<<)+(z<<)+ch-''; ch=getchar();}
return z*mk;
}
int n,a[];
long long f[][],g[][];
long long mx=;
int main(){//freopen("ddd.in","r",stdin);
cin>>n;
for(int i=;i<=n;++i) a[i]=rd();
f[][]=a[]-a[];
for(int i=;i<n;++i){
f[i][]=f[i-][]+abs(a[i]-a[i+])*(i&?:-);
f[i][]=f[i-][]+abs(a[i]-a[i+])*(i&?-:);
//cout<<(a[i]-a[i+1])*(i&1?1:-1)<<" "<<(a[i]-a[i+1])*(i&1?-1:1)<<endl;
g[i][]=min(g[i-][],f[i][]);
g[i][]=min(g[i-][],f[i][]);
mx=max(mx,f[i][]-g[i][]);
mx=max(mx,f[i][]-g[i][]);
//cout<<f[i][0]<<" "<<f[i][1]<<" "<<g[i][0]<<" "<<g[i][1]<<endl;
}
cout<<mx<<endl;
return ;
}
codeforces 788A Functions again的更多相关文章
- Codeforces 788A Functions again - 贪心
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian super ...
- CodeForces 788A - Functions again [ DP ]
反着求一遍最大连续子序列(前项依赖) #include <bits/stdc++.h> using namespace std; #define LL long long ; int n; ...
- codeforces C. Functions again
题意:给定了一个公式,让你找到一对(l,r),求解出公式给定的F值. 当时没有想到,我把(-1)^(i-l)看成(-1)^i,然后思路就完全错了.其实这道题是个简单的dp+最长连续子序列. O(n)求 ...
- codeforces 407 div1 A题(Functions again)
codeforces 407 div1 A题(Functions again) Something happened in Uzhlyandia again... There are riots on ...
- Codeforces E. Bash Plays with Functions(积性函数DP)
链接 codeforces 题解 结论:\(f_0(n)=2^{n的质因子个数}\)= 根据性质可知\(f_0()\)是一个积性函数 对于\(f_{r+1}()\)化一下式子 对于 \[f_{r+1} ...
- Codeforces 757 E Bash Plays with Functions
Discription Bash got tired on his journey to become the greatest Pokemon master. So he decides to ta ...
- 【codeforces 757E】Bash Plays with Functions
[题目链接]:http://codeforces.com/problemset/problem/757/E [题意] 给你q个询问; 每个询问包含r和n; 让你输出f[r][n]; 这里f[0][n] ...
- [Codeforces 757E] Bash Plays with Functions (数论)
题目链接: http://codeforces.com/contest/757/problem/E?csrf_token=f6c272cce871728ac1c239c34006ae90 题目: 题解 ...
- 【codeforces 789C】Functions again
[题目链接]:http://codeforces.com/contest/789/problem/C [题意] 看式子. [题解] 考虑最后的答案区间; 如果那个区间是从奇数位置的数字开始的; 那么奇 ...
随机推荐
- netty]--最通用TCP黏包解决方案
netty]--最通用TCP黏包解决方案:LengthFieldBasedFrameDecoder和LengthFieldPrepender 2017年02月19日 15:02:11 惜暮 阅读数:1 ...
- vue-14-过滤
过滤器可以用在两个地方:mustache 插值和 v-bind 表达式 <!-- in mustaches --> {{ message | capitalize }} <!-- i ...
- 《Python》进程收尾线程初识
一.数据共享 from multiprocessing import Manager 把所有实现了数据共享的比较便捷的类都重新又封装了一遍,并且在原有的multiprocessing基础上增加了新的机 ...
- centos7创建docker tomcat镜像
1 准备宿主系统 准备一个 CentOS 7操作系统,具体要求如下: 必须是 64 位操作系统 建议内核在 3.8 以上 通过以下命令查看您的 CentOS 内核: 1 # uname -r 2 安装 ...
- 64-65管道,rm与rmdir
听说linux根目录tmp文件夹内是临时文件.用久了会产生很多垃圾文件 请问下面的临时文件怎么维护清理?全部没用删除,还是? /tmp 公用的临时文件存储点 linux下的文件结构 /bin 二进制可 ...
- embedding与word2vec
embedding是指将目标向量化,常用于自然语言处理(如:Word2Vec).这种思想的意义在于,可以将语义问题转换为数值计算问题,从而使计算机能够便捷处理自然语言问题.如果采用传统的One-hot ...
- TEST mathjax
这里是第一个公式 $ F = ma^2 $ \[ \text{Reinforcement Learning} \doteq \pi_* \\ \quad \updownarrow \\ \pi_* \ ...
- CPU 架构 —— ARM 架构
linux 系统查看 CPU 架构命令: $ arch armv7l $ uname -m armv7l # -m:--machine # 进一步查看处理器信息 $ cat /proc/cpuinfo ...
- 安装最新nginx
另外:http://nginx.org/en/linux_packages.html#mainline https://blog.csdn.net/hiram/article/details/5178 ...
- 构建NDK交叉编译链
有时我们需要单独编译个c文件,生成一个ELF在Android上面跑,NDK提供了一个 make-standalone-toolchain.sh 脚本,用于生成一套特定平台的交叉编译工具链 使用方法如下 ...