[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 ...
随机推荐
- VHDL 数字时钟设计
序言 这个是我在做FPGA界的HelloWorld--数字钟设计时随手写下的,再现了数字钟设计的过程 目标分析 时钟具有时分秒的显示,需6个数码管.为了减小功耗采用扫描法显示 按键设置时间,需要对按键 ...
- 牛客练习赛7 E 珂朵莉的数列(树状数组+爆long long解决方法)
https://www.nowcoder.com/acm/contest/38/E 题意: 思路: 树状数组维护.从大佬那里学习了如何处理爆long long的方法. #include<iost ...
- Oracle AMERICAN改成简体中文
64位Oracle连接32位PLSQL_Developer时,在PLSQL_Developer安装的目录中新建了一个TXT文件,之后更名为start.bat,内容如下: @echo off set p ...
- form提交不刷新,不跳转页面
利用 iframe 标签 ,后台form处理可以返回void <form action="" method="post" target="nm_ ...
- Cannot set property 'onclick' of null的问题
转载自: https://my.oschina.net/ximidao/blog/351017 摘要: 测试点击事件的时候浏览器报错,提示Uncaught TypeError: Cannot set ...
- .NetCore Session.Redis
首先创建ASP.NET CORE Web项目,然后按如下顺序操作.1.添加nuget程序包: Microsoft.AspNetCore.Session; Microsoft.AspNetCore.Da ...
- Qt532.QString_填充字符
1.代码: void MainWindow::on_pushButton_clicked() { QString str = "; QString str01 = str.leftJusti ...
- Android的数据的存储方式
数据的存储方式,总的来说分为三种: ① 文件存储: * SharedPreferences存储 * SD卡存储 ---- Environment * 数据库存储 ---- SQLite .MySQL. ...
- java高并发解决方案
高并发的解决方法有两种: 1.使用缓存 2.使用生成静态页面: (代码质量,不要性能低下的sql和代码.有的一条sql搞定的事,有人用了多个循环才能搞定.取决于程序员的经验!(还有就是从最基础的地方优 ...
- C#获取路径中最后一个文件夹的名字
using System; using System.IO; namespace ConsoleApplication1 { class Program { static void Main(stri ...