codeforces-446A-DZY Loves Sequences
来源:互联网 发布:橡胶木与橡木区别 知乎 编辑:程序博客网 时间:2024/06/05 08:27
codeforces-446A-DZY Loves Sequences
time limit per test1 second memory limit per test256 megabytes
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.
input
6
7 2 3 1 5 6
output
5
Note
You can choose subsegment a2, a3, a4, a5, a6 and change its 3rd element (that is a4) to 4.
题目链接:cf-446A
题目大意:给出n长度的序列,问可以任意改变一个值,求最长的严格递增子序列长度
题目思路:用ret数组记录前面比当前值小的连续有几个。
例如:a[]: 7 2 3 1 5 6
ret[]: 1 1 2 1 2 3
以下是代码:
#include <vector>#include <map>#include <set>#include <algorithm>#include <iostream>#include <cstdio>#include <cmath>#include <cstdlib>#include <string>#include <cstring>using namespace std;int a[100010];int ret[100010];int main(){ int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i - 1] < a[i]) ret[i] = ret[i - 1] + 1; else ret[i] = 1; } int maxnum = 0; int cur = 0; for (int i = n - 1; i >= 0; i--) { maxnum = max(maxnum,ret[i - 1] + 1); maxnum = max(maxnum,cur + 1); if (i == 0 || i == n - 1 || a[i - 1] + 1 < a[i + 1]) { maxnum = max(maxnum,ret[i - 1] + cur + 1); } if (a[i] < a[i + 1]) cur++; else cur = 1; } cout << maxnum << endl; return 0;}
- Codeforces 446A DZY Loves Sequences
- CodeForces 446A DZY Loves Sequences
- codeforces 446A DZY Loves Sequences
- CodeForces 446-A.DZY Loves Sequences
- codeforces-446A-DZY Loves Sequences
- CodeForces 446A DZY Loves Sequences
- Codeforces 446A DZY Loves Sequences【dp】
- Codeforces 446A —— DZY Loves Sequences(DP)
- Codeforces Round #FF 446A DZY Loves Sequences
- CodeForces 446A DZY Loves Sequences(DP)
- CF 446A DZY Loves Sequences
- Codeforces Round #FF (Div. 2)446A - DZY Loves Sequences(最长上升子序列变形)
- codeforces#FF(div2) DZY Loves Sequences
- CodeForces-447C DZY Loves Sequences
- CodeForces 447C###C. DZY Loves Sequences
- Codeforces Round #FF (Div. 1) A. DZY Loves Sequences 动态规划
- cf446A DZY Loves Sequences
- C. DZY Loves Sequences
- 关于OPC自动化接口编程(OPCDAAuto.dll)几点注意问题
- VBScript
- 基于HTML5的WebGL电信网管3D机房监控应用
- View 和ViewGroup
- 欢迎使用CSDN-markdown编辑器
- codeforces-446A-DZY Loves Sequences
- java synchronized/wait/notify/互斥/同步
- where 1<> 1 和where 1=1的用法
- 多线程——NSOperation
- photoshop抠图
- QT5.5下的USB HID热插拔检测,未全部完成,聊作记录。
- Android下adb用法总结
- ecshop 数据库调试技巧 【强烈推荐】
- Htmlparser 中的各种Filter介绍