题意:给定了一个公式,让你找到一对(l,r),求解出公式给定的F值。

  当时没有想到,我把(-1)^(i-l)看成(-1)^i,然后思路就完全错了。其实这道题是个简单的dp+最长连续子序列。

  O(n)求最长连续子序列代码

    ll maxx=, sum=, now=;
for (int i=; i<n; i++) { //数列1-n
sum+=dp1[i];
maxx=max(maxx, sum);
if (sum<) sum=;
}

  其实我们可以发现,其实正负是交错的,那么我们只要用两个dp(正负相反)的数组来存,再求一次最长连续子序列就好了。

/*  gyt
Live up to every day */
#include <stdio.h>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <cstring>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <time.h>
#define PI acos(-1)
using namespace std;
typedef long long ll;
typedef double db;
const int maxn = 1e5+;
const ll maxm = 1e7;
const int mod = ;
const int INF = <<;
const db eps = 1e-;
const ll Max=1e19;
ll a[maxn], dp1[maxn], dp2[maxn]; void solve() {
int n; scanf("%d", &n);
for (int i=; i<=n; i++) {
scanf("%lld", &a[i]);
}
memset(dp1, , sizeof(dp1));
memset(dp2, , sizeof(dp2));
int f=;
for (int i=; i<=n-; i++) {
dp1[i]=abs(a[i]-a[i+])*f;
dp2[i]=abs(a[i]-a[i+])*(-f);
f = -f;
}
ll maxx=, sum=, now=;
for (int i=; i<n; i++) {
sum+=dp1[i];
maxx=max(maxx, sum);
if (sum<) sum=;
}
sum=;
for (int i=; i<n; i++) {
sum+=dp2[i];
maxx=max(maxx, sum);
if (sum<) sum=;
}
cout<<maxx<<endl;
}
int main() {
int t=;
//freopen("in.txt", "r", stdin);
//scanf("%d", &t);
for (int T=; T<=t; T++) {
solve();
}
}

codeforces C. 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

    …… 原题: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandia ...

  3. CodeForces 788A - Functions again [ DP ]

    反着求一遍最大连续子序列(前项依赖) #include <bits/stdc++.h> using namespace std; #define LL long long ; int 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. PHP使用UTF8编码读取ACCESS的乱码问题解决方案(转)

    PHP使用UTF8编码读取ACCESS的乱码问题解决方案 http://it.xwstudy.com/readnews.php?id=627 来源:本站编辑 发布日期:2013-05-27 已有 17 ...

  2. 四 sys模块

    1 sys.argv 命令行参数List,第一个元素是程序本身路径 2 sys.exit(n) 退出程序,正常退出时exit(0) 3 sys.version 获取Python解释程序的版本信息 4 ...

  3. serv-U使用

    该软件是设置ftp服务器的 可以百度查询ftp服务器安装攻略,如 https://jingyan.baidu.com/article/cb5d6105c00bba005c2fe0ca.html 问题: ...

  4. centos 7 redis-4.0.11 主从

    redis-master:192.168.199.223 redis-slave: 192.168.199.224 cd /opt wget http://download.redis.io/rele ...

  5. Windows配置Java环境

    https://jingyan.baidu.com/article/84b4f56598d88b60f7da3272.html

  6. python基础入门学习2

    python 整体注释:选中所有然后CTRL+? 运算符 + - * /   **  %  // 布尔值 true 真  False 假 !=不等于 <>不等于 算数运算,赋值运算,比较运 ...

  7. JAVA 基本数据结构--数组、链表、ArrayList、Linkedlist、hashmap、hashtab等

    概要 线性表是一种线性结构,它是具有相同类型的n(n≥0)个数据元素组成的有限序列.本章先介绍线性表的几个基本组成部分:数组.单向链表.双向链表:随后给出双向链表的C.C++和Java三种语言的实现. ...

  8. HDU-1459.非常可乐(BFS )

    这道题TLE了很多次,原来一直以为将数字化为最简可以让运算更快,但是去了简化之后才发现,真正耗时的就是化简....还和队友学到了用状态少直接数组模拟刚就能过... 本题大意:给出可乐的体积v1,给出两 ...

  9. mysql、oracle 中按照拼音首字母排序

    mysql中按照拼音首字母排序 convert(name using gbk) ASC 注:name 为字段名称 oracle中按照拼音首字母排序 nlssort(enterprise_name,'N ...

  10. CentOS查看进程、杀死进程、启动进程等常用命令

    关键字: linux 查进程.杀进程.起进程 1.查进程     ps命令查找与进程相关的PID号:     ps a 显示现行终端机下的所有程序,包括其他用户的程序.     ps -A 显示所有程 ...