……

原题:

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 ;
}

最新文章

  1. C++ 利用 libxl 将 Excel 文件转化为 Xml 文件
  2. 1.iOS直播ijkplayer(第一周)
  3. struts2与velocity的整合有两种方式
  4. C#获取内存图像数据流的方法
  5. 使用PowerShell读、写、删除注册表键值
  6. VMware Workstation虚拟机使用ISO映像文件
  7. 解决设置redmineblacklog的按钮无效问题
  8. IOS 基于TCP的socket通信详解(原创)
  9. linq中的分组和排序
  10. BZOJ 2463: [中山市选2009]谁能赢呢?(新生必做的水题)
  11. JSONP 详解
  12. 声明式RESTful客户端在asp.net core中的应用
  13. 【转】vmware 安装 osx 无法登录 appstore 的解决办法 (伪造smbios设备信息)
  14. Vue 中使用 viewerjs
  15. python(nmap模块、多线程模块)
  16. shell 编程中的 知识点 - 突然一下子就明白很多东西了
  17. JDK并发包中ExecutorCompletionService使用
  18. Centos 7 部署Kubernetes(K8S)集群
  19. oracle一些工作笔记
  20. PHP图像处理

热门文章

  1. 遍历存储所有物体添加到列表中(使用GameObject.activeSelf进行判断)
  2. 【转】用深度学习做crowd density estimation
  3. js 判断某个元素是否隐藏或显示
  4. (C/C++学习笔记) 二十. 文件和流
  5. leetcode python 001
  6. TBody scrollbar 设置
  7. 全栈框架mk-js
  8. java.util.concurrent ThreadPoolExecutor源码分析
  9. 8.Python爬虫实战一之爬取糗事百科段子
  10. 前端关于列表的基础 day47