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; } else b[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; else c[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; }