[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 ...
 
随机推荐
- python学习之re库
			
正则表达式库re是非常重要的一个库. 首先正则表达式有两种表示类型,一种是raw string类型(原生字符串类型),也就是我们经常看到的r' '的写法,另一种是不带r的写法,称为string类型. ...
 - Java常见异常:Exception in thread "main" java.lang.NoClassDefFoundError
			
在某一路径下执行编译好的class文件出错. 异常如下: E:\liwy>java Test98 Exception in thread "main" java.lang.N ...
 - IIS客户端没有权限
			
运行CMDicacls c:\ /setintegritylevel M
 - 删除node_modules文件
			
删除node_modules文件夹报错:路径太长,无法删除. npm install rimraf -g rimraf node_modules
 - python 删除文件夹
			
只能删除空文件夹,删除非空文件夹会报错 >>> import os >>> os.rmdir("/tmp/ssh-GyoPWOFZ47") Tr ...
 - 文件编码检测.ZC
			
1.今天(20181101) 发现 g文件中的 xml头 和 文件编码不一致,最后发现 貌似是我搞错了,人家的文件 编码方式写的是对的. 我发现的现象是:XML里面写的是"GBK" ...
 - 人脸识别ArcfaceDemo for Windows 分享
			
Demo_for_Windows https://github.com/ArcJonSnow/Demo_for_Windows Arcsoft ArcfaceDemo for Windows, VS2 ...
 - python + lisp  hy的新手注记2   eval, HyModel and python AST
			
来自我在Stack Overflow上的提问,https://stackoverflow.com/questions/51675355/how-to-eval-a-cond-case-and-retu ...
 - Qt5模型/视图结构-视图(View)
			
实现自定义的View,可继承自QAbstractItemView类,对所需的纯虚函数进行重定义与实现,对于QAbstractItemView类中的纯虚函数,在子类中必须进行重定义,但不一定要实现,可根 ...
 - JAVA基础知识总结:一到二十二全部总结
			
>一: 一.软件开发的常识 1.什么是软件? 一系列按照特定顺序组织起来的计算机数据或者指令 常见的软件: 系统软件:Windows\Mac OS \Linux 应用软件:QQ,一系列的播放器( ...