Remove One Element

Here Insert Picture Description
Here Insert Picture Description

Meaning of the questions: Please delete the length of the rise of a sub-sequence after.

Ideas: The number of increments were recorded in front of the i-th and the following number of increments,

Finally, through all i, the maximum value because only two situations:

The number is incremented by 1. i-th

2. When the number of increments arr [i-1] <arr [i + 1], do not the i-th (i-1) number of incremental preceding + (i + 1) behind.

#include <bits/stdc++.h>
#define SIS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ll long long
#define INF 0x3f3f3f3f
#define mod 998244353
using namespace std;
const int N=2e5+5;
int gcd(int a,int b)
{
	return b==0?a:gcd(b,a%b);
}
int dp[2][N];
int a[N];
int main()
{
    SIS;
   int n;
   cin>>n;
   for(int i=1;i<=n;i++)
   {
       cin>>a[i];
       if(a[i]>a[i-1])dp[0][i]=dp[0][i-1]+1;
       else dp[0][i]=1;
   }
   for(int i=n;i>=1;i--)
   {
       if(a[i+1]>a[i])dp[1][i]=dp[1][i+1]+1;
       else dp[1][i]=1;
   }
   int ans=0;
   for(int i=1;i<=n;i++)
   {
      ans=max(ans,dp[0][i]);
      if(a[i-1]<a[i+1])
        ans=max(ans,dp[0][i-1]+dp[1][i+1]);
   }
   cout<<ans<<endl;


   return 0;
}

Published 73 original articles · won praise 4 · Views 2217

Guess you like

Origin blog.csdn.net/qq_43619680/article/details/103995966
Recommended