最长递增子序列(模板)

最长公共子序列
(模板) 时间复杂度nlog(n);

原理解释

我推荐看这篇博客,慢慢理解。

#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=100010;
const int inf=0x3f3f3f3f;
int a[maxn];
int dp[maxn];
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        fill(dp,dp+n,inf);
        for(int i=0;i<n;i++)
            scanf("%d",&a[i]);
        for(int i=0;i<n;i++)
        {
            *lower_bound(dp,dp+n,a[i])=a[i];    
        }
        printf("%d\n",lower_bound(dp,dp+n,inf)-dp);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_39576425/article/details/76935022