580A - Kefa and First Steps

思路:dp

dp[i]表示包括前i个元素中a[i]在内的最大增序列。

代码:

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int a[N];
int dp[N];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    dp[0]=1;
    int ans=1;
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=1;i<n;i++)
    {
        if(a[i]>=a[i-1])dp[i]=dp[i-1]+1;
        else dp[i]=1;
        ans=max(dp[i],ans);
    }
    cout<<ans<<endl;
    return 0;
}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-10-13
  • 2021-06-24
  • 2021-08-24
  • 2022-12-23
  • 2021-12-28
  • 2021-09-01
猜你喜欢
  • 2021-06-29
  • 2022-12-23
  • 2021-05-16
  • 2021-06-07
  • 2021-10-24
  • 2022-12-23
  • 2021-08-29
相关资源
相似解决方案