POJ 2533 Longest Ordered Subsequence(最长上升子序列(NlogN)
Description
A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequence of the given numeric sequence (a1, a2, ..., aN) be any sequence (ai1, ai2, ..., aiK), where 1 <= i1 < i2 < ... < iK <= N. For example, sequence (1, 7, 3, 5, 9, 4, 8) has ordered subsequences, e. g., (1, 7), (3, 4, 8) and many others. All longest ordered subsequences are of length 4, e. g., (1, 3, 5, 8).
Your program, when given the numeric sequence, must find the length of its longest ordered subsequence.
Input
The first line of input file contains the length of sequence N. The second line contains the elements of sequence - N integers in the range from 0 to 10000 each, separated by spaces. 1 <= N <= 1000
Output
Output file must contain a single integer - the length of the longest ordered subsequence of the given sequence.
Sample Input
7 1 7 3 5 9 4 8
Sample Output
4
思路
模板题
#include<stdio.h> const int maxn = 1005; int binary(int pos,int len,int *ans,int *dp) { int left = 1,right = len; while (left < right) { int mid = left + ((right - left) >> 1); if (dp[mid] < ans[pos] ) left = mid + 1; else right = mid; } return right; } int main() { int N,len = 1; int ans[maxn],dp[maxn]; scanf("%d",&N); for (int i = 1;i <= N;i++) scanf("%d",&ans[i]); dp[1] = ans[1]; for (int i = 2;i <= N;i++) { if (ans[i] > dp[len]) dp[++len] = ans[i]; else { int pos = binary(i,len,ans,dp);dp[pos] = ans[i]; //找到第一个大于等于ans[i]的位置,更新dp[pos]的最小值 //pos = low_bound(dp+1,dp+len,ans[i]) - dp; } } printf("%d\n",len); return 0; }
POJ 2533 Longest Ordered Subsequence(最长上升子序列(NlogN)的更多相关文章
- poj 2533 Longest Ordered Subsequence 最长递增子序列
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4098562.html 题目链接:poj 2533 Longest Ordered Subse ...
- POJ 2533 - Longest Ordered Subsequence - [最长递增子序列长度][LIS问题]
题目链接:http://poj.org/problem?id=2533 Time Limit: 2000MS Memory Limit: 65536K Description A numeric se ...
- poj 2533 Longest Ordered Subsequence 最长递增子序列(LIS)
两种算法 1. O(n^2) #include<iostream> #include<cstdio> #include<cstring> using namesp ...
- POJ 2533 Longest Ordered Subsequence 最长递增序列
Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequenc ...
- POJ 2533 Longest Ordered Subsequence(裸LIS)
传送门: http://poj.org/problem?id=2533 Longest Ordered Subsequence Time Limit: 2000MS Memory Limit: 6 ...
- POJ - 2533 Longest Ordered Subsequence与HDU - 1257 最少拦截系统 DP+贪心(最长上升子序列及最少序列个数)(LIS)
Longest Ordered Subsequence A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let ...
- 题解报告:poj 2533 Longest Ordered Subsequence(最长上升子序列LIS)
Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequence ...
- POJ 2533 Longest Ordered Subsequence(DP 最长上升子序列)
Longest Ordered Subsequence Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 38980 Acc ...
- POJ 2533 Longest Ordered Subsequence(LIS模版题)
Longest Ordered Subsequence Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 47465 Acc ...
随机推荐
- 发布新款博客皮肤SimpleMemory
感谢 sevennight 又为大家精心设计了一款简约风格的博客皮肤 —— SimpleMemory. 大家可以通过这篇博文感受一下实际的效果:开园子啦(浅谈移动端以及h5的发展) 如果您喜欢这款皮肤 ...
- parsing XML document from class path resource
遇到问题:parsing XML document from class path resource [spring/resources] 解决方法:项目properties— source—remo ...
- 项目分享一:在项目中使用 IScroll 所碰到的那些坑
最近做了个 WEB APP 项目,用到了大名鼎鼎的 IScroll,滚动的效果的确很赞,但是坑也是特别多,下面总结一下,希望自后来者有帮助. 该项目现已开源在 github 上,https://git ...
- 3DMax 物体选择方法
全选: Ctrl + A, 取消选择:Ctrl +D 加选:ctrl+鼠标左键:减选:alt+鼠标 窗口与交叉:下面红框内的右边的按钮, 是切换两种模式: 选择模式一:只要选框碰到物体边缘, 就可选中 ...
- C语言变参数函数
#include<iostream> #include<stdarg.h> using namespace std; int sum(int cnt, ...){ va_lis ...
- linux基础-第十一单元 系统监控
第十一单元 系统监控 系统监视和进程控制工具-top和free top命令的功能 TOP是一个动态显示过程,即可以通过用户按键来不断刷新当前状态.如果在前台执行该命令,它将独占前台,直到用户终止该程序 ...
- Linux下运行memcached失败
Linux下运行memcached失败 1.错误信息如下 [root@localhost ~]# memcached can't run as root without the -u switch 2 ...
- json写入new_hello文件
#写入new文件 import json dic = {'name':'alex'} i = 8 s = 'hello' l = [11,22] f = open("new_hello&qu ...
- Java--剑指offer(7)
31.求出1~13的整数中1出现的次数,并算出100~1300的整数中1出现的次数?为此他特别数了一下1~13中包含1的数字有1.10.11.12.13因此共出现6次,但是对于后面问题他就没辙了.AC ...
- 开发错误记录5-Failed to sync Gradle project ‘HideTitleDemo’
今天用Android Studio2.0创建的项目,到Android Studio1.5打开,直接报错: 意思就是内存空间不够,要在gradle.properties 文件中进行内存设置,因为是从高版 ...