dp测模板ORZ 51nod 1134最长递增子序列

在劝退边缘徘徊…… 复习了下lower_bound 和 upper_bound

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5;
int dp[maxn];
int a[maxn];
int len=0;
int n;
void lis()
{
    len = 0;
    dp[0]=-0x3f3f3f3f;
    for(int i=1; i<=n; i++)
    {
        if(a[i]>dp[len]) dp[++len]=a[i];
        else
        {
            int pos=lower_bound(dp+1,dp+len+1,a[i])-dp;
            dp[pos]=a[i];
        }
    }
}
int main()
{

    cin>>n;
    for(int i = 1; i<=n; i++) cin>>a[i];
    lis();
    cout<<len<<endl;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_41156122/article/details/81294194
今日推荐