【cf789C】Functions again(最大子序列和)
题意
给你一个数组a[1..n]。有一个函数\(f(l,r)=\sum_{i=l}^{r-1}\left| a[i]-a[i+1]\right| (-1)^{l-i}(1\le l< r\le n)\),求f最大值。
题解
令b[i]=|a[i]-a[i+1]|(-1)^i,c[i]=-b[i]。那么答案就是b数组和c数组的最大子序列和中较大的一个。
代码
const int N=101000;
ll n,a[N],s;
ll ans,mb,mc;
int main() {
scanf("%lld",&n);
rep(i,0,n){
scanf("%lld",a+i);
if(i){
s+=abs(a[i-1]-a[i])*(i&1?1:-1);
mc=min(-s,mc);
mb=min(s,mb);
ans=max(s-mb,ans);
ans=max(-s-mc,ans);
}
}
printf("%lld\n",ans);
return 0;
}
【cf789C】Functions again(最大子序列和)的更多相关文章
- CF789C. Functions again
/* CF789C. Functions again http://codeforces.com/contest/789/problem/C 水题 题意:求数组中的连续和的最大值 */ #includ ...
- poj 1080 ——Human Gene Functions——————【最长公共子序列变型题】
Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 17805 Accepted: ...
- POJ 1080 Human Gene Functions -- 动态规划(最长公共子序列)
题目地址:http://poj.org/problem?id=1080 Description It is well known that a human gene can be considered ...
- Human Gene Functions POJ 1080 最长公共子序列变形
Description It is well known that a human gene can be considered as a sequence, consisting of four n ...
- poj 1080 Human Gene Functions (最长公共子序列变形)
题意:有两个代表基因序列的字符串s1和s2,在两个基因序列中通过添加"-"来使得两个序列等长:其中每对基因匹配时会形成题中图片所示匹配值,求所能得到的总的最大匹配值. 题解:这题运 ...
- HDU 1080 Human Gene Functions - 最长公共子序列(变形)
传送门 题目大意: 将两个字符串对齐(只包含ACGT,可以用'-'占位),按照对齐分数表(参见题目)来计算最后的分数之和,输出最大的和. 例如:AGTGATG 和 GTTAG ,对齐后就是(为了表达对 ...
- Human Gene Functions
Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 18053 Accepted: 1004 ...
- poj1080--Human Gene Functions(dp:LCS变形)
Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 17206 Accepted: ...
- hdu1080 Human Gene Functions() 2016-05-24 14:43 65人阅读 评论(0) 收藏
Human Gene Functions Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
随机推荐
- hibernate坑边闲话3
could not initialize proxy - no Session] with root cause org.hibernate.LazyInitializationException: ...
- NFV论文集(三)综述
一 文章名称:Dependability of the NFV Orchestrator: State of the Art and Research Challenges 发表时间:2018 期刊来 ...
- Two distinct points CodeForces - 1108A (签到)
You are given two segments [l1;r1][l1;r1] and [l2;r2][l2;r2] on the xx-axis. It is guaranteed that l ...
- Summer sell-off CodeForces - 810B (排序后贪心)
Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying ...
- Day4 Python基础之数据类型(三)
计算机中,一切皆为对象 世界万物,皆为对象,一切对象皆可分类 ------------------------------------我是分割线---------------------------- ...
- .net之httphandler小记
本地调试代码遇到的一个问题,没有走URL路由器(UrlReWriter : IHttpHandlerFactory),于是网上科普了一下原理,主要有两点: 1.asp.net在处理http请求时,会由 ...
- rem移动端适配方案
一. rem vs em 单位 定义 特点 rem font size of the root element 以根元素字体大小为基准 em font size of the element 以父元素 ...
- 2 Interrupting Appropriately
1 Interrupting someone politely e.g. Excuse me for interrupting, but may I ask a question? Sure. Of ...
- [转帖]ulimit、limits.conf、sysctl和proc文件系统
ulimit.limits.conf.sysctl和proc文件系统 来源:https://blog.csdn.net/weixin_33918114/article/details/86882372 ...
- sqlserver常用语法
--临时表 IF OBJECT_ID('tempdb..#Entry') is not null BEGIN DROP TABLE #Entry END ------------------- ...