Description

给出长度为n的数组,找出这个数组的最长上升子序列

Input

第一行:输入N,为数组的长度(2=<N<=50000)

第二行:N个值,表示数组中元素的值(109<=a[i]<=109)

Output

输出最长上升子序列的长度

Sample Input

5

-6 4 -2 10 5

Sample Output

3


  1. #include<iostream>
  2. #include<cstring>
  3. #include<algorithm>
  4. using namespace std;
  5. const int INF=0x7f7f7f7f;
  6. const int maxn=50005;
  7. int n, g[maxn], d[maxn],a[maxn];
  8. int main()
  9. {
  10. cin>>n;
  11. for(int i=0;i<n;i++)
  12. {
  13. cin>>a[i];
  14. }
  15. fill(g, g+n, INF);
  16. int maxnum=-1;
  17. for(int i=0; i<n; i++)
  18. {
  19. int j = lower_bound(g, g+n, a[i]) - g;
  20. d[i] = j+1;
  21. if(maxnum<d[i])
  22. maxnum=d[i];
  23. g[j] = a[i];
  24. }
  25. cout<<maxnum<<endl;
  26. return 0;
  27. }

[ACM]NEFUOJ-最长上升子序列的更多相关文章

  1. 【ACM】最长公共子序列 - 动态规划

    最长公共子序列 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 咱们就不拐弯抹角了,如题,需要你做的就是写一个程序,得出最长公共子序列.tip:最长公共子序列也称作最 ...

  2. 【二分】【最长上升子序列】HDU 5489 Removed Interval (2015 ACM/ICPC Asia Regional Hefei Online)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5489 题目大意: 一个N(N<=100000)个数的序列,要从中去掉相邻的L个数(去掉整个区间 ...

  3. Rectangles(第七届ACM省赛原题+最长上升子序列)

    题目链接: http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=1255 描述 Given N (4 <= N <= 100)  rec ...

  4. ACM/ICPC 之 最长公共子序列计数及其回溯算法(51Nod-1006(最长公共子序列))

    这道题被51Nod定为基础题(这要求有点高啊),我感觉应该可以算作一级或者二级题目,主要原因不是动态规划的状态转移方程的问题,而是需要理解最后的回溯算法. 题目大意:找到两个字符串中最长的子序列,子序 ...

  5. ACM: 强化训练-Beautiful People-最长递增子序列变形-DP

    199. Beautiful People time limit per test: 0.25 sec. memory limit per test: 65536 KB input: standard ...

  6. [ACM] hdu 1025 Constructing Roads In JGShining's Kingdom (最长递增子序列,lower_bound使用)

    Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65 ...

  7. hdu1503 最长公共子序列变形

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1503 题意:给出两个字符串 要求输出包含两个字符串的所有字母的最短序列.注意输出的顺序不能 ...

  8. hdu 5748(求解最长上升子序列的两种O(nlogn)姿势)

    Bellovin Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): Accepte ...

  9. uva111动态规划之最长公共子序列

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=74662#problem/C     A B C D E C - Largest Rect ...

  10. 04_最长上升子序列问题(LIS)

    来源:刘汝佳<算法竞赛入门经典--训练指南> P60 问题6: 问题描述:给定n个整数a1,a2,...,an,按从左到右的顺序选出尽量多的整数,组成一个上升子序列(子序列可以理解为:删除 ...

随机推荐

  1. rdlc报表需要显示的时间格式

    [仅取当前时间的年月日]=FormatDateTime(System.DateTime.Now.ToLongDateString().ToString()) [仅取数据库保存的时间的年月日]=form ...

  2. oracle 存过调试 stepinto stepover stepout

    step into:单步执行,遇到子函数就进入并且继续单步执行(简而言之,进入子函数): step over:在单步执行时,在函数内遇到子函数时不会进入子函数内单步执行,而是将子函数整个执行完再停止, ...

  3. servlet - 从本地下载图片

    import javax.servlet.ServletException;import javax.servlet.ServletOutputStream;import javax.servlet. ...

  4. centos7(虚拟机)下安装nginx

    centos7(虚拟机)下安装nginx 安装前准备 gcc yum install gcc-c++ pcre yum install -y pcre pcre-devel zlib yum inst ...

  5. Two Sum:给出一个整数数组,返回两个数的下标值,令其和等于一个指定的目标值 #Leetcode

    // Given nums = [2, 7, 11, 15], target = 9, // Because nums[0] + nums[1] = 2 + 7 = 9, // return [0, ...

  6. cf823div2C

    cf823div2C 题目链接 题目 给你两个字符串\(s_1,s_2\).每次操作可以让\(s_1\)的前k个和\(s_2\)的后k个交换.询问是否可以通过多次上述操作,使得\(s_1=s_2\). ...

  7. Python - XSS-href

    参考资料: https://owasp-skf.gitbook.io/asvs-write-ups/cross-site-scripting-href-xss-href/kbid-3-cross-si ...

  8. Realtek 平台一些乱七八糟的编译环境设置

    1. 129x 系列之后的就推荐用ubuntu 16.04了 省去一些GCC ,tar,quilt 等问题 Android 平台: sudo apt-get install u-boot-tools ...

  9. sql生成code

  10. api加密与校验

    一.函数代码 /** * 校验 * @data (请求的数组) * @salt (加密盐) * */ private function verify(array $data, $salt){ $sig ...