最大上升子序列

Description

  
  The world financial crisis is quite a subject. Some people are more relaxed while others are quite anxious. John is one of them. He is very concerned about the evolution of the stock exchange. He follows stock prices every day looking for rising trends. Given a sequence of numbers p1, p2,...,pn representing stock prices, a rising trend is a subsequence pi1 < pi2 < ... < pik, with i1 < i2 < ... < ik. John’s problem is to find very quickly the longest rising trend.

Input

  Each data set in the file stands for a particular set of stock prices. A data set starts with the length L (L ≤ 100000) of the sequence of numbers, followed by the numbers (a number fits a long integer). 
White spaces can occur freely in the input. The input data are correct and terminate with an end of file.

Output

  The program prints the length of the longest rising trend. 
For each set of data the program prints the result to the standard output from the beginning of a line.

Sample Input

6
5 2 1 4 5 3
3
1 1 1
4
4 3 2 1

Sample Output

3
1
1 题目大意:给出一串序列,要求输出最大上升子序列。 分析:用动态规划,效率高;如果后一个数比前一个大,上升序列长度加1,否则长度减1,将后者较小的数代替前者。 代码如下:
#include <iostream>
#include <cstdio>
#include <algorithm>
const int maxn=100005;
using namespace std;
int a[maxn],dp[maxn],len,n;
int find(int x)
{
int l=1,r=len,mid;
while(l<=r)
{
mid=(l+r)>>1;
if(x>dp[mid])
l=mid+1;
else
r=mid-1;
}
return l;
}
int main()
{
while(scanf("%d",&n)==1)
{
len=0;
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
for(int i=1;i<=n;i++)
{
int k=find(a[i]);
dp[k]=a[i];
len=max(len,k);
}
printf("%d\n",len);
}
return 0;
}

LIS-Program E的更多相关文章

  1. POJ3903:Stock Exchange(LIS)

    题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87125#problem/E 题目: Description The world ...

  2. HDU 1160 FatMouse's Speed(要记录路径的二维LIS)

    FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  3. POJ 2533 动态规划入门 (LIS)

    Longest Ordered Subsequence Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 42914 Accepte ...

  4. HDU 1069 Monkey and Banana(二维偏序LIS的应用)

    ---恢复内容开始--- Monkey and Banana Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ...

  5. POJ 2533 Longest Ordered Subsequence(LIS模版题)

    Longest Ordered Subsequence Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 47465   Acc ...

  6. POJ 3903:Stock Exchange(裸LIS + 二分优化)

    http://poj.org/problem?id=3903 Stock Exchange Time Limit: 1000MS   Memory Limit: 65536K Total Submis ...

  7. hdu----(1950)Bridging signals(最长递增子序列 (LIS) )

    Bridging signals Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  8. IGS_学习笔记05_IREP开发Concurrent Program为客户化集合接口(案例)

    20150819 Created By BaoXinjian

  9. POJ 1631 Bridging signals(LIS O(nlogn)算法)

    Bridging signals Description 'Oh no, they've done it again', cries the chief designer at the Waferla ...

  10. 动态规划——E (LIS())最长上升子序列

    E - LIS Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Stat ...

随机推荐

  1. MFC编程入门之六(对话框:创建对话框模板和修改对话框属性)

    本节开始为大家讲解偏向应用的知识--创建对话框.  对话框,大家应该很熟悉了,在我们常用的软件中大多都有对话框界面,例如,360安全卫士的主界面其实就是对话框,知识它做了很多美工方面的工作,将其大大美 ...

  2. 深入浅出RxJava(一:基础篇)

    RxJava正在Android开发者中变的越来越流行.唯一的问题就是上手不容易,尤其是大部分人之前都是使用命令式编程语言.但是一旦你弄明白了,你就会发现RxJava真是太棒了. 这里仅仅是帮助你了解R ...

  3. Android LayoutInflater深度解析 给你带来全新的认识

      转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/38171465 , 本文出自:http://blog.csdn.net/lmj ...

  4. Python核心编程-基础2

    open() 和 file() 函数会同时存在, 完成相同的功能.一般说来, 我们建议使用 open() 来读写文件, 在您想说明您在处理文件对象时使用 file() , 例如 if instance ...

  5. 解决点击a标签返回页面顶部的问题

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. 20145218 《Java程序设计》第01次实验报告

    北京电子科技学院(BESTI)实验报告 课程:Java程序设计 班级:1452 指导教师:娄嘉鹏 实验日期:2016.04.08 实验名称:Java开发环境的熟悉(Linux + Eclipse) 实 ...

  7. 4.2 EF的CRUD控制器代码

    以下的例子以留言本作为依据. 1.添加 public ActionResult Create() { return View(); } // // POST: /Contact/Create [Htt ...

  8. [saiku] 使用 Apache Phoenix and HBase 结合 saiku 做大数据查询分析

    saiku不仅可以对传统的RDBMS里面的数据做OLAP分析,还可以对Nosql数据库如Hbase做统计分析. 本文简单介绍下一个使用saiku去查询分析hbase数据的例子. 1.phoenix和h ...

  9. python实现微信打飞机游戏

    环境:Ubuntu 16.04 LTS Python 2.7.11 +  Pygame + Pycharm 代码: # -*- coding: UTF-8 -*- import pygame, ran ...

  10. UNIX高级环境编程学习

    1-5实例 控制字符:ctrl + 另一个键.control + D或者^D是默认的文件结束符(EOF字符).