给出长度为N的数组,找出这个数组的最长递增子序列。(递增子序列是指,子序列的元素是递增的)

例如:5 1 6 8 2 4 5 10,最长递增子序列是1 2 4 5 10。

 
Input
第1行:1个数N,N为序列的长度(2 <= N <= 50000)
第2 - N + 1行:每行1个数,对应序列的元素(-10^9 <= S[i] <= 10^9)
Output
输出最长递增子序列的长度。
Input示例
8
5
1
6
8
2
4
5
10
Output示例
5
 #include <iostream>
#include <stdio.h>
#include <cstring>
#include <algorithm>
using namespace std;
#define N 50010
int a[N],c[N];
int n,len=;
int Find(int x)
{
int l=,r=len,mid;
while(l<=r){
mid=(l+r)>>;
if(x>c[mid]) l=mid+;
else r=mid-;
}
return l;
}
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
for(int i=;i<=n;i++){
int k=Find(a[i]);
c[k]=a[i];
len=max(len,k);
}
printf("%d\n",len);
return ;
}

STL 求最长上升子序列:

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

LIS 51Nod 1134 最长递增子序列的更多相关文章

  1. 51nod 1134 最长递增子序列

    题目链接:51nod 1134 最长递增子序列 #include<cstdio> #include<cstring> #include<algorithm> usi ...

  2. 51nod 1134最长递增子序列

    1134 最长递增子序列 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题  收藏  关注 给出长度为N的数组,找出这个数组的最长递增子序列.(递增子序列是指,子序列的元素 ...

  3. 51Nod - 1134 最长递增子序列【动态规划】

    给出长度为N的数组,找出这个数组的最长递增子序列.(递增子序列是指,子序列的元素是递增的) 例如:5 1 6 8 2 4 5 10,最长递增子序列是1 2 4 5 10. Input 第1行:1个数N ...

  4. LCS 51Nod 1134 最长递增子序列

    给出长度为N的数组,找出这个数组的最长递增子序列.(递增子序列是指,子序列的元素是递增的) 例如:5 1 6 8 2 4 5 10,最长递增子序列是1 2 4 5 10.   Input 第1行:1个 ...

  5. 51Nod 1134 最长递增子序列(动态规划O(nlogn))

    #include <iostream> #include <algorithm> #include <stdio.h> #define MAXN 50010 usi ...

  6. 51Nod:1134 最长递增子序列

    动态规划 修改隐藏话题 1134 最长递增子序列  基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题  收藏  关注 给出长度为N的数组,找出这个数组的最长递增子序列.(递 ...

  7. 51nod 1376 最长递增子序列的数量(线段树)

    51nod 1376 最长递增子序列的数量 数组A包含N个整数(可能包含相同的值).设S为A的子序列且S中的元素是递增的,则S为A的递增子序列.如果S的长度是所有递增子序列中最长的,则称S为A的最长递 ...

  8. 51nod 1218 最长递增子序列 | 思维题

    51nod 1218 最长递增子序列 题面 给出一个序列,求哪些元素可能在某条最长上升子序列中,哪些元素一定在所有最长上升子序列中. 题解 YJY大嫂教导我们,如果以一个元素结尾的LIS长度 + 以它 ...

  9. 51 Nod 1134 最长递增子序列 (动态规划基础)

    原题链接:1134 最长递增子序列 题目分析:长度为  的数列  有多达  个子序列,但我们应用动态规划法仍可以很高效地求出最长递增子序列().这里介绍两种方法. 先考虑用下列变量设计动态规划的算法. ...

随机推荐

  1. P3387缩点(tarjan+拓扑排序+线性dp)

    题目描述 给定一个 n个点 m 条边有向图,每个点有一个权值,求一条路径,使路径经过的点权值之和最大.你只需要求出这个权值和. 允许多次经过一条边或者一个点,但是,重复经过的点,权值只计算一次. 输入 ...

  2. PHP 中 new static 和 new self 的区别

            今天老大在公司 问了一下  new static  和 new self 的区别 公司十个程序 竟然没有一个回答上来 后面画面自补 ... 本屌丝回家后 就百度了解了下 这二者区别 : ...

  3. qt creator源码全方面分析(2-5)

    目录 Creating Wizards in Code 介绍 相关类 IWizardFactory的设置器和获取器 Creating Wizards in Code 介绍 如果基于模板的自定义向导提供 ...

  4. VFP CursorAdapter 起步一(作者:Doug Hennig 译者:fbilo)

    CursorAdapter 类是 VFP 8 中最重要的新功能之一,因为它提供了一种简单易用.接口统一的访问远程数据源方式.在这个月的文章里,Dung Hennig 将向你展示 CursorAdapt ...

  5. 论文《learning to link with wikipedia》

    learning to link with wikipedia 一.本文目标: 如何自动识别非结构化文本中提到的主题,并将其链接到适当的Wikipedia文章中进行解释. 二.主要借鉴论文: Miha ...

  6. 不重启 清空tomcat日志

    1.重定向方法清空文件 [root@localhost logs]# du -h catalina.out  查看文件大小17M catalina.out[root@localhost logs]# ...

  7. light oj 1035 - Intelligent Factorial Factorization 素因子分解

    1035 - Intelligent Factorial Factorization Given an integer N, you have to prime factorize N! (facto ...

  8. codewars--js--Two Joggers--求最小公倍数、最大公约数

    问题描述: Two Joggers Description Bob and Charles are meeting for their weekly jogging tour. They both s ...

  9. 皮皮家园干活~万元web前端系统班在线课程点击免费领取

    点击添加群聊 今天在整理百度云盘里的资源,这几年累计了不少软件和教程. 在这特殊的时期里,先给大家分享一波.图片里的文件夹就是目录, 加入群聊免费领取 好资源就是要大家一起共享, 你们也不用到处在网上 ...

  10. Android中使用Intent的Action和Data属性实现点击按钮跳转到拨打电话和发送短信

    场景 点击拨打电话按钮,跳转到拨打电话页面 点击发送短信按钮,跳转到发送短信页面 注: 博客: https://blog.csdn.net/badao_liumang_qizhi 关注公众号 霸道的程 ...