最大上升子序列

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. Hbase之Exception

    [hadoop@master hbase-1.2.2]$ ./bin/hbase shell2016-08-25 13:53:56,898 WARN [main] util.NativeCodeLoa ...

  2. COM组件(MFC篇)

    目录 第1章创建进程内组件    1 1.1 目标    1 1.2 创建项目    3 1.2.1 VC++6.0    3 1.2.2 VC++2010    4 1.2.3 VC++6.0与VC ...

  3. div布局

    Margin: Margin属性用于设置两个元素之间的距离. Padding: Padding属性用于设置一个元素的边框与其内容的距离. Clear: 使用Float属性设置一行有多个DIV后(多列) ...

  4. HTTP协议中PUT和POST使用区别 【转载】

    有的观点认为,应该用 POST来创建一个资源,用PUT来更新一个资源:有的观点认为,应该用PUT来创建一个资源,用POST来更新一个资源:还有的观点认为可以用PUT和 POST中任何一个来做创建或者更 ...

  5. Linux配置邮箱发送(MUTT/MSMTPQ)

    配置邮箱发送 http://www.ilanni.com/?p=10589

  6. (28)odoo中css可用颜色对照表

    颜色 颜色英文代码 形像颜色 HEX格式 RGB格式 LightPink 浅粉红 #FFB6C1 255,182,193 Pink 粉红 #FFC0CB 255,192,203 Crimson 猩红 ...

  7. cd命令进入D盘

    CD命令是更改目录命令如果要进入D盘 不用这个命令 直接输入 D: 回车 即可要是你非要使用CD命令那要加参数/DCD D:系统只是认为你想在系统中记忆一下D盘所以还是返回原先目录例:D盘下有一个目录 ...

  8. IOS-错误总结

    1,警告:"xoxoxoxo"  is deprecated解决办法:查看xoxoxoxo的这个方法的文档,替换掉这个方法即可.2,警告:Declaration of " ...

  9. EasyUI DataGrid View

    http://www.jeasyui.com/easyui/datagrid-detailview.js 前提一定要引入:datagrid-detailview.js主要是三个属性和普通的datgag ...

  10. SQL的常用语句

    select * from g_members where id between '16' and '31' order by id desc 倒序排列 select * from g_members ...