Codeforces Round #FF (Div. 2)446A - DZY Loves Sequences(最长上升子序列变形)
来源:互联网 发布:c语言做窗口按钮 编辑:程序博客网 时间:2024/05/17 00:00
AC代码:
#include <stdio.h>#include <string.h>#define Max 100100#define ll long long#define max(a,b) a>b?a:b;ll a[Max],l[Max],r[Max];int main(){ll n,p,i,j,ans;while(~scanf("%lld",&n)){memset(a,0,sizeof(a)); memset(l,0,sizeof(l)); memset(r,0,sizeof(r));ans=1;for(i=0;i<n;i++)scanf("%lld",&a[i]);if(n==1)printf("1\n");else if(n==2)printf("2\n");else{l[0]=1;for(i=1;i<n;i++){if(a[i]>a[i-1])l[i]=l[i-1]+1;elsel[i]=1;}r[n-1]=1;for(i=n-2;i>=1;i--){if(a[i+1]>a[i])r[i]=r[i+1]+1;elser[i]=1;}for(i=n-2;i>=1;i--){if(a[i-1]+1<a[i+1])ans=max(ans,l[i-1]+1+r[i+1]);}for(i=1;i<n;i++){if(a[i]<=a[i-1])ans=max(ans,l[i-1]+1);}for(i=0;i<n-1;i++){if(a[i]>=a[i+1])ans=max(ans,r[i+1]+1);}printf("%lld\n",ans);}}return 0;}
0 0
- Codeforces Round #FF (Div. 2)446A - DZY Loves Sequences(最长上升子序列变形)
- 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 446A DZY Loves Sequences
- codeforces 447C DZY Loves Sequences(最长上升子序列变体)
- Codeforces Round #FF (Div. 2) C - DZY Loves Sequences (DP)
- Codeforces Round #FF (Div. 二):C. DZY Loves Sequences
- Codeforces Round #FF (Div. 2) Problem A DZY Loves Hash
- 无聊看了PHP的加解密
- (原创)学习过程中遇到了不清楚的方法关于StringUtils中 isNotEmpty 和isNotBlank
- Intel 主板 USB 3.0 XHCI控制器端口配置
- 数组 【java笔记】
- 什么是socket(网络大神略过,网络小白比如我进)
- Codeforces Round #FF (Div. 2)446A - DZY Loves Sequences(最长上升子序列变形)
- 幕人网门窗幕墙论坛介绍
- hdu1180诡异的楼梯(广搜)
- Shell scriptp
- ACM小技巧
- 使用c3p0数据库连接池时出现com.mchange.v2.resourcepool.TimeoutException
- Cannot implicitly convert type 'System.Web.HttpPostedFile' to 'System.Web.HttpPostedFileBase'
- 珍爱收益,远离点融
- CocoStudio sample讲解 SampleChangeEquip 换装系统