Codeforces Round #FF (Div. 2) C. DZY Loves Sequences
来源:互联网 发布:郭美美事件 知乎 编辑:程序博客网 时间:2024/05/16 02:16
题目: DZY Loves Sequences
给你n 个数, 让你至多可以改变一个数的情况下,求得最长的严格递增子序列的长度。
智商捉急。 。 首先预处理出来对于每个位置i, 以这个位置为左端点的最长序列的长度, 和以他为右端点的最长序列的长度。
之后遍历一遍,判断每个位置是否改变,求得max。
code:
#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespace std;#define N 100005#define INF 1000000000int n, num[N], l[N], r[N] , ans;int main(){ //freopen("in.txt", "r", stdin); scanf("%d", &n); for(int i=1; i<=n; i++) { scanf("%d", &num[i]); } num[0]= -100; num[n+1]= INF; for(int i=1; i<=n; i++) { if(num[i] > num[i-1]) l[i] = l[i-1]+1; else l[i] = 1; } for(int i=n; i>=1; i--) { if(num[i]<num[i+1]) r[i] = r[i+1] + 1; else r[i] = 1; } ans=0; for(int i=1; i<=n; i++) { ans = max(ans, max(r[i], l[i])); if(i>1 && num[i] <= num[i-1]) ans = max(ans, l[i-1] +1 ); if(i<n && num[i] >= num[i+1]) ans = max(ans, r[i+1] +1); if(i>1 && i<n && num[i-1]+1 < num[i+1]) ans = max(ans, l[i-1] + r[i+1] +1); } printf("%d\n", ans); return 0;}
0 0
- Codeforces Round #FF (Div. 2):C. DZY Loves Sequences
- Codeforces Round #FF (Div. 2) Problem C DZY Loves Sequences
- Codeforces Round #FF (Div. 2)C - DZY Loves Sequences
- Codeforces Round #FF (Div. 2)-C. DZY Loves Sequences
- Codeforces Round #FF (Div. 2)C. DZY Loves Sequences
- Codeforces Round #FF (Div. 2) C. DZY Loves Sequences
- Codeforces Round #FF (Div. 2) C. DZY Loves Sequences
- Codeforces Round #FF (Div. 2) C DZY Loves Sequences
- Codeforces Round #FF (Div. 2)C. DZY Loves Sequences
- Codeforces Round #FF (Div. 2)C. DZY Loves Sequences
- Codeforces Round #FF (Div. 2)-C. DZY Loves Sequences
- Codeforces Round #FF (Div. 2) C. DZY Loves Sequences
- Codeforces Round #FF (Div. 二):C. DZY Loves Sequences
- Codeforces Round #FF (Div. 2) C - DZY Loves Sequences (DP)
- Codeforces Round #FF (Div. 2/C)/Codeforces446A_DZY Loves Sequences(DP)
- Codeforces Round #FF (Div. 2)446A - DZY Loves Sequences(最长上升子序列变形)
- Codeforces Round #FF (Div. 1) C - DZY Loves Fibonacci Numbers
- Codeforces Round #FF (Div. 1) C. DZY Loves Fibonacci Numbers
- 分布式搜索elasticsearch配置文件详解
- Cisco VPN Client Reason 442: Failed to Enable Virtual Adapter
- 远程首次连接mysql速度慢的解决方法
- Android小知识——TextView的高的自适应
- coco2d-x2.2.4 时间倒记时显示
- Codeforces Round #FF (Div. 2) C. DZY Loves Sequences
- key 串口
- Hadoop-2.4.1学习之以伪分布模式部署Hadoop
- 获取android的各种路径
- VC和Linux C下可用的控制台进度代码
- jQuery中attr()和prop()的区别,修改checked属性
- android ics SystemUI详解
- 玩App怎么赚钱(二)
- Android使用Ant批量打包