……

原题:

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的更多相关文章

  1. Codeforces 788A Functions again - 贪心

    Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian super ...

  2. CodeForces 788A - Functions again [ DP ]

    反着求一遍最大连续子序列(前项依赖) #include <bits/stdc++.h> using namespace std; #define LL long long ; int n; ...

  3. codeforces C. Functions again

    题意:给定了一个公式,让你找到一对(l,r),求解出公式给定的F值. 当时没有想到,我把(-1)^(i-l)看成(-1)^i,然后思路就完全错了.其实这道题是个简单的dp+最长连续子序列. O(n)求 ...

  4. codeforces 407 div1 A题(Functions again)

    codeforces 407 div1 A题(Functions again) Something happened in Uzhlyandia again... There are riots on ...

  5. Codeforces E. Bash Plays with Functions(积性函数DP)

    链接 codeforces 题解 结论:\(f_0(n)=2^{n的质因子个数}\)= 根据性质可知\(f_0()\)是一个积性函数 对于\(f_{r+1}()\)化一下式子 对于 \[f_{r+1} ...

  6. 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 ...

  7. 【codeforces 757E】Bash Plays with Functions

    [题目链接]:http://codeforces.com/problemset/problem/757/E [题意] 给你q个询问; 每个询问包含r和n; 让你输出f[r][n]; 这里f[0][n] ...

  8. [Codeforces 757E] Bash Plays with Functions (数论)

    题目链接: http://codeforces.com/contest/757/problem/E?csrf_token=f6c272cce871728ac1c239c34006ae90 题目: 题解 ...

  9. 【codeforces 789C】Functions again

    [题目链接]:http://codeforces.com/contest/789/problem/C [题意] 看式子. [题解] 考虑最后的答案区间; 如果那个区间是从奇数位置的数字开始的; 那么奇 ...

随机推荐

  1. U帮忙U盘装系统工具使用教程

    在用U盘装系统时首先我们需要了解一下U帮忙U盘启动盘的制作以及BIOS设置U盘启动和U盘装系统步骤后才能让操作更顺利的完成,下面就来说说U帮忙U盘装系统工具使用教程,希望对大家有所帮助! 如果您不了解 ...

  2. bzoj1651

    题解: 前缀和维护 f[a]++,f[b+1]-- 然后F[i]+=f[i-1] 代码: #include<bits/stdc++.h> using namespace std; ; in ...

  3. java③

    1.变量是什么? 变量====>一个数据在内存中 存储空间的表示! 在程序运行期间可以发生变化! *变量名 可以 迅速的从内存中 查询出 指定的变量! 2.数据类型: 数据类型 一共分为两种: ...

  4. It is never too late!

    整理着过去的学习笔记,零零碎碎的,偶尔夹杂着当时的心境. 泛泛的学着东西,不很系统,不很深入,倒像是在拾海,有时捡捡贝壳,有时抓抓螃蟹.叹服大海的神奇,还没来得及深钻某个领域. (以下内容写于2016 ...

  5. Java:下拉列表绑定后台数据

    后台传进来一个List集合,存着某对象集合,将其显示在下拉列表 一.HTML代码 页面有个下拉列表,如图所示: <td style="width:30%"> <s ...

  6. centos7 新装系统网络配置

    [root@localhost ~]# cat /etc/sysconfig/grub GRUB_TIMEOUT= GRUB_DISTRIBUTOR="$(sed 's, release . ...

  7. 每天CSS学习之caption-side

    caption-side是CSS2的属性,其作用是规定标题的位置在表格的上面还是下面. 1.top:默认值,将表格标题定位在表格之上.如下例子: caption{ caption-side:top; ...

  8. 《Python》hashlib模块、configparser模块、logging模块

    一.hashlib模块 Python的hashlib模块中提供了常见的摘要算法,如md5,sha1等等. 摘要算法又称哈希算法.散列算法.它通过一个函数,把任意长度的数据转换为一个长度固定的字符串(通 ...

  9. 用matlab绘制中国地图

    reference:https://jingyan.baidu.com/article/870c6fc36fdacfb03ee4be58.html shp: http://muchong.com/ht ...

  10. 浅谈如何正确给table加边框

    一般来说,给表格加边框都会出现不同的问题,以下是给表格加边框后展现比较好的方式 <style> table,table tr th, table tr td { border:1px so ...