美文网首页C++C语言编程语言爱好者
BZOJ1669: [Usaco2006 Oct]Hungry

BZOJ1669: [Usaco2006 Oct]Hungry

作者: 小火小火车车车 | 来源:发表于2016-09-27 20:40 被阅读0次

题意
给定长度为n的序列,求最长上升子序列
复杂度
O(nlogn)
题解
网上有很多关于最长上升子序列nlogn的求法,我这里不在过多叙述。

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int n,a[5001],last[5001],ans;
int main()
{
    memset(last,127,sizeof(last));
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    last[0]=0;
    for(int i=1;i<=n;i++)
    {
        int tmp=lower_bound(last,last+n,a[i])-last;
        last[tmp]=min(last[tmp],a[i]);
        ans=max(ans,tmp);
    }
    printf("%d",ans);
    return 0;
}

相关文章

  • BZOJ1669: [Usaco2006 Oct]Hungry

    题意给定长度为n的序列,求最长上升子序列复杂度O(nlogn)题解网上有很多关于最长上升子序列nlogn的求法,我...

  • 06

    Are You Hungry? Are you hungry? (Shrug your shoulders and...

  • Good for the Soul

    Oct. 14, 2006 – Oct. 23 marks the fifth anniversary of Ap...

  • OnNationalDay

    Oct.1st is the national day of China.In 1949.Oct.1st,...

  • “little hungry”、“great hungry”

    小饥饿是解决温饱衣食住行,大饥饿则需要解决内心的空虚,用自己的方式达到心底平静。

  • 单例模式

    1:饿汉式 public class Hungry { private static final Hungry...

  • 麦豆悦读英文绘本讲师训练营【13期】

    14/21 绘本赏析 "The very hungry hungry caterpillar" 13期 1301 ...

  • hungry

    when i start use eglish write diary,i don't know these ...

  • Hungry

    不管有没有天赋 她都准备往诗人方向跑 Due to 她发现诗淫的爱情和Sex 比正常人多得多 PS :a 、饿狼传...

  • 20170629

    (一) " I'm really hungry now. "" Ok~ just Stay Hungry, Sta...

网友评论

    本文标题:BZOJ1669: [Usaco2006 Oct]Hungry

    本文链接:https://www.haomeiwen.com/subject/usqhyttx.html