题目传送门

 /*
DP:先用l,r数组记录前缀后缀上升长度,最大值会在三种情况中产生:
1. a[i-1] + 1 < a[i+1],可以改a[i],那么值为l[i-1] + r[i+1] + 1
2. l[i-1] + 1 3. r[i+1] + 1 //修改a[i]
*/
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std; const int MAXN = 1e5 + ;
const int INF = 0x3f3f3f3f;
int a[MAXN];
int l[MAXN], r[MAXN];
int n; int main(void) //Codeforces Round #FF (Div. 1) A. DZY Loves Sequences
{
scanf ("%d", &n); int ans = ;
for (int i=; i<=n; ++i)
{
scanf ("%d", &a[i]);
l[i] = ;
if (i > && a[i] > a[i-]) l[i] = l[i-] + ;
} for (int i=n; i>=; --i)
{
r[i] = ;
if (i < n && a[i] < a[i+]) r[i] = r[i+] + ;
} for (int i=; i<=n; ++i)
{
ans = max (ans, l[i]); ans = max (ans, r[i]);
if (i > && i < n && a[i-] + < a[i+]) ans = max (ans, l[i-] + r[i+] + );
if (i > ) ans = max (ans, l[i-] + );
if (i < n) ans = max (ans, r[i+] + );
} printf ("%d\n", ans); return ;
}

DP Codeforces Round #FF (Div. 1) A. DZY Loves Sequences的更多相关文章

  1. Codeforces Round #FF (Div. 1) A. DZY Loves Sequences 动态规划

    A. DZY Loves Sequences 题目连接: http://www.codeforces.com/contest/446/problem/A Description DZY has a s ...

  2. Codeforces Round #FF (Div. 1) A. DZY Loves Sequences

    题目链接: http://www.codeforces.com/contest/446/problem/A 题解: dp1[x]表示以x结尾的最大严格升序连续串,dp2[x]表示以x开头的最大严格升序 ...

  3. Codeforces Round #FF (Div. 2) C. DZY Loves Sequences

    解题报告:输入一个数列,选取一个子数列,要求最多只能改动这个子数列中的一个数,使得这个子数列是严格的升序的(严格升序没有相等的) 我的做法是,第一步把这个 数列的每个升序的子数列都找出来,然后看这些子 ...

  4. Codeforces Round #FF (Div. 1) B. DZY Loves Modification 优先队列

    B. DZY Loves Modification 题目连接: http://www.codeforces.com/contest/446/problem/B Description As we kn ...

  5. Codeforces Round #FF (Div. 2) D. DZY Loves Modification 优先队列

    D. DZY Loves Modification time limit per test 2 seconds memory limit per test 256 megabytes input st ...

  6. Codeforces Round #FF (Div. 1) B. DZY Loves Modification

    枚举行取了多少次,如行取了i次,列就取了k-i次,假设行列单独贪心考虑然后相加,那么有i*(k-i)个交点是多出来的:dpr[i]+dpc[k-i]-i*(k-i)*p 枚举i取最大值.... B. ...

  7. Codeforces Round #FF (Div. 2):B. DZY Loves Strings

    B. DZY Loves Strings time limit per test 1 second memory limit per test 256 megabytes input standard ...

  8. Codeforces Round #FF (Div. 2)__E. DZY Loves Fibonacci Numbers (CF447) 线段树

    http://codeforces.com/contest/447/problem/E 题意: 给定一个数组, m次操作, 1 l r 表示区间修改, 每次 a[i] +  Fibonacci[i-l ...

  9. Codeforces Round #FF (Div. 2) A. DZY Loves Hash

    DZY has a hash table with p buckets, numbered from 0 to p - 1. He wants to insert n numbers, in the ...

随机推荐

  1. Linux下汇编语言学习笔记42 ---

    这是17年暑假学习Linux汇编语言的笔记记录,参考书目为清华大学出版社 Jeff Duntemann著 梁晓辉译<汇编语言基于Linux环境>的书,喜欢看原版书的同学可以看<Ass ...

  2. JVM 总结

    面试 java 虚拟机 jvm 基础 jvm Write Once Run EveryWhere >jar 包可以在任何兼容jvm上运行 >jvm 适配器 屏蔽掉底层差异 >内存管理 ...

  3. POJ 2456_Aggressive cows

    题意: 给定N个位置,把C头牛分别放入,求相邻两头牛的最大距离. 分析: 即为求两头牛之间最小距离的最大值.二分搜索答案. 代码: #include<iostream> #include& ...

  4. Java并发包——线程池

    Java并发包——线程池 摘要:本文主要学习了Java并发包中的线程池. 部分内容来自以下博客: https://www.cnblogs.com/dolphin0520/p/3932921.html ...

  5. JavaScript为字符串添加样式

    <script type="text/javascript"> var txt="Hello World!" document.write(&quo ...

  6. Ubuntu 16.04安装RapidSVN

    使用RabbitVCS有一些不完美,比如没有把文件增加到版本库的功能,导致无法提交等问题,现在再次安装RapidSVN来弥补这些缺点. 安装: sudo apt-get install rapidsv ...

  7. mysql设置datetime默认值为now

    mysql设置datetime默认值为now MYSQL-TIMESTAMP数据类型的默认值与自动更新问题 http://blog.csdn.net/scogeek/article/details/5 ...

  8. 作为一名CEO

    你 不能怕得罪人 不能奢望完成工作的时候 有太多的愉悦感 你 必须要去做左右为难但左右亦可的 操蛋决策 你 得脸皮够厚 肚囊儿宽超 什么事情都能快速消化 哪怕 是 一坨屎 你 还得 决不放弃 永不言败 ...

  9. 1076. Forwards on Weibo (30)【树+搜索】——PAT (Advanced Level) Practise

    题目信息 1076. Forwards on Weibo (30) 时间限制3000 ms 内存限制65536 kB 代码长度限制16000 B Weibo is known as the Chine ...

  10. Linux system log avahi-daemon[3640]: Invalid query packet.

    2014-06-11 Check the Linux system log find the errorr: Jun  9 11:18:49 hostname avahi-daemon[3640]: ...