pta L2-014 列车调度(dp下降序列的个数)

题目链接

求下降序列的个数:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5+10;
const int INF=0x3f3f3f3f;

int a[maxn],dp[maxn];

int main()
{
    int n;
    cin>>n;
    for(int i = 0;i < n;i++) cin>>a[i];
    fill(dp,dp+n,INF);
    for(int i = 0; i < n; i++) *lower_bound(dp,dp+n,a[i])=a[i];
    cout<<lower_bound(dp,dp+n,INF)-dp<<endl;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_42754600/article/details/88899818