[CodeForces - 447C] C - DZY Loves Sequences
C - DZY Loves Sequences
DZY has a sequence a, consisting of n integers.
We'll call a sequence ai, ai + 1, ..., aj (1 ≤ i ≤ j ≤ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment.
Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing.
You only need to output the length of the subsegment you find.
Input
The first line contains integer n (1 ≤ n ≤ 105). The next line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109).
Output
In a single line print the answer to the problem — the maximum length of the required subsegment.
Example
67 2 3 1 5 6
5
Note
You can choose subsegment a2, a3, a4, a5, a6 and change its 3rd element (that is a4) to 4.
题目意思是,给出一个序列,只能改变一个数的值,使最长上升子序列的长度最长.
这题其实挺水.我们设f[i]为第i个数左边的最长上升子序列的长度,g[i]为第i个数右边的最长上升子序列的长度,
然后在满足a[i-1]+1<=a[i+1]-1的情况下,求一下max(g[i]+f[i]+1)就行了.然后居然WA了......
后来发现,还有种情况没发现,就是以i结尾或开头的子序列,也有可能是最优的→_→
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
],f1[],f2[],n,ans;
int read(){
,f=; char ch=getchar();
'){if (ch=='-') f=-f; ch=getchar();}
+ch-',ch=getchar();
return x*f;
}
int main(){
n=read(); ; i<=n; i++) a[i]=read();
){puts(;}
){puts(;}
f1[]=,f1[]=;
; i<=n; i++) ]>a[i-]) f1[i]=f1[i-]+; ;
f2[n]=,f2[n-]=;
; i>=; i--) ]>a[i+]) f2[i]=f2[i+]+; ;
ans=max(ans,f2[]+); ans=max(ans,f1[n]+);
; i<n; i++){
]+<=a[i+]-) ans=max(ans,f1[i]+f2[i]+);
ans=max(ans,f1[i]+);
ans=max(ans,f2[i]+);
}
printf("%d",ans);
;
}
[CodeForces - 447C] C - DZY Loves Sequences的更多相关文章
- Codeforces 447 C DZY Loves Sequences【DP】
题意:给出一列数,在这个序列里面找到一个连续的严格上升的子串,现在可以任意修改序列里面的一个数,问得到的子串最长是多少 看的题解,自己没有想出来 假设修改的是a[i],那么有三种情况, 1.a[i]& ...
- 【Codeforces 446A】DZY Loves Sequences
[链接] 我是链接,点我呀:) [题意] 让你找一段连续的区间 使得这一段区间最多修改一个数字就能变成严格上升的区间. 问你这个区间的最长长度 [题解] dp[0][i]表示以i为结尾的最长严格上升长 ...
- Codeforces 447C - DZY Loves Sequences
447C - DZY Loves Sequences 思路:dp 代码: #include<bits/stdc++.h> using namespace std; #define ll l ...
- codeforces#FF DIV2C题DZY Loves Sequences(DP)
题目地址:http://codeforces.com/contest/447/problem/C C. DZY Loves Sequences time limit per test 1 second ...
- 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 ...
- DP Codeforces Round #FF (Div. 1) A. DZY Loves Sequences
题目传送门 /* DP:先用l,r数组记录前缀后缀上升长度,最大值会在三种情况中产生: 1. a[i-1] + 1 < a[i+1],可以改a[i],那么值为l[i-1] + r[i+1] + ...
- Codeforces Round #FF (Div. 2):C. DZY Loves Sequences
C. DZY Loves Sequences time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Codeforces Round #FF 446A DZY Loves Sequences
预处理出每一个数字能够向后延伸多少,然后尝试将两段拼起来. C. DZY Loves Sequences time limit per test 1 second memory limit per t ...
- cf446A DZY Loves Sequences
A. DZY Loves Sequences time limit per test 1 second memory limit per test 256 megabytes input standa ...
随机推荐
- HDU 5445 Food Problem(多重背包+二进制优化)
http://acm.hdu.edu.cn/showproblem.php?pid=5445 题意:现在你要为运动会提供食物,总共需要提供P能量的食物,现在有n种食物,每种食物能提供 t 能量,体积为 ...
- JVM介绍
1. 什么是JVM? JVM是Java Virtual Machine(Java虚拟机)的缩写,JVM是一种用于计算设备的规范,它是一个虚构出来的计算机,是通过在实际的计算机上仿真模拟各种计算机功能来 ...
- 如何创建R包并将其发布在 CRAN / GitHub 上--转载
转载--https://www.analyticsvidhya.com/blog/2017/03/create-packages-r-cran-github/ 什么是 R 包?我开始创建 R 包的原因 ...
- _itemmod_creation_enchant
该表控制物品产生时自动获得随机附魔效果 comment 备注 entry 物品entry slot 附魔位置1-5,这些位置都可以用来产生自带附魔效果 groupId 附魔组Id 对就_ ...
- _itemmod_refresh
-- 随机FM刷新设置-- 小技巧:很多服所说的装备鉴定效果可以通过这个实现,也可以对物品重新生成新的附魔--详细解说一下鉴定系统如何实现--1首先在_itemmod_enchant_groups中添 ...
- (一)PHP简介
什么是 PHP? PHP 是 "PHP Hypertext Preprocessor" 的首字母缩略词 PHP 是一种被广泛使用的开源脚本语言 PHP 脚本在服务器上执行 PHP ...
- Servlet中web.xml的配置
引言:这是一个采用原生Servlet开发的项目的一个简要配置,在这里记录一下,以便以后用到了 可以直接copy,如又侵权,请联系本博主. <?xml version="1.0" ...
- 在选择列表中无效,因为该列既不包含在聚合函数中,也不包含在 GROUP BY 子句
在选择列表中无效,因为该列既不包含在聚合函数中,也不包含在 GROUP BY 子句 突然看到这个问题,脑袋一蒙,不知道啥意思,后来想想,试图把select里的选项放到后面,问题自然解决! 下面这 ...
- python3.5学习第一章
在python中,变量赋值或者其他语句后不需要加”:“ python中,缩进特别重要! 条件语句和循环语句,要加”:“ 一.变量赋值 name = "cecelia"name2 = ...
- Lua和C++交互 学习记录之五:全局数组交互
主要内容转载自:子龙山人博客(强烈建议去子龙山人博客完全学习一遍) 部分内容查阅自:<Lua 5.3 参考手册>中文版 译者 云风 制作 Kavcc vs2013+lua-5.3.3 1 ...