Topic Portal
/*DP: First use the l,r array to record the prefix suffix rise length, the maximum value will be generated in three cases: 1. a[i-1] + 1 < a[i+1], you can change A[i], then the value is l[i-1] + r[i+1] + 1 2. l[i -1] + 1 3. R[I+1] + 1//modify A[i]*/#include<cstdio>#include<algorithm>#include<cstring>using namespacestd;Const intMAXN = 1e5 +Ten;Const intINF =0x3f3f3f3f;intA[MAXN];intL[MAXN], R[MAXN];intN;intMainvoid)//codeforces Round #FF (Div. 1) A. Dzy Loves Sequences{scanf ("%d", &n);intAns =0; for(intI=1; i<=n; ++i) {scanf ("%d", &A[i]); L[i]=1; if(I >1&& A[i] > a[i-1]) L[i] = l[i-1] +1; } for(intI=n; i>=1; --i) {R[i]=1; if(I < n && A[i] < a[i+1]) R[i] = r[i+1] +1; } for(intI=1; i<=n; ++i) {ans= Max (ans, l[i]); Ans =Max (ans, r[i]); if(I >1&& i < n && a[i-1] +1< a[i+1]) ans = max (ans, l[i-1] + r[i+1] +1); if(I >1) ans = max (ans, l[i-1] +1); if(I < n) ans = max (ans, r[i+1] +1); } printf ("%d\n", ans); return 0;}
DP codeforces Round #FF (Div. 1) A. Dzy Loves Sequences