本文主要是介绍codeforces#FF DIV2C题DZY Loves Sequences(DP),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目地址:http://codeforces.com/contest/447/problem/C
代码如下;
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <queue>
#include <map>
#include<algorithm>
using namespace std;
int a[200000], b[200000], c[200000];
int main()
{int n, i, j, max1=-1;scanf("%d",&n);for(i=0;i<n;i++)scanf("%d",&a[i]);b[0]=1;for(i=1;i<n;i++){if(a[i]>a[i-1]){b[i]=b[i-1]+1;}elseb[i]=1;}c[n-1]=1;for(i=n-2;i>=0;i--){if(a[i]<a[i+1])c[i]=c[i+1]+1;elsec[i]=1;}if(n==1)printf("1\n");else{max1=2;if(max1<b[n-2]+1)max1=b[n-2]+1;if(max1<c[1]+1)max1=c[1]+1;for(i=1;i<=n-2;i++){if(a[i+1]-a[i-1]>1){if(max1<b[i-1]+c[i+1]+1)max1=b[i-1]+c[i+1]+1;}else{if(max1<b[i-1]+1)max1=b[i-1]+1;if(max1<c[i+1]+1)max1=c[i+1]+1;}}printf("%d\n",max1);}return 0;
}
这篇关于codeforces#FF DIV2C题DZY Loves Sequences(DP)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!