POJ - 3903 Stock Exchange(LIS最长上升子序列问题)
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
Description
Input
White spaces can occur freely in the input. The input data are correct and terminate with an end of file.
Output
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
Hint
#include<cstdio>
int a[100001], f[100001];
int main()
{
int n, k, l, r, mid;
while (scanf("%d",&n)==1)
{
for (int i = 0; i < n; i++)
scanf("%d",&a[i]);
k = 0;
f[0] = -1; //赋初值,小于0即可
for (int i = 0; i < n; i++)
{
if (a[i] > f[k])
{
k++;
f[k] = a[i]; //每找到一个就保存到f【】数组里
}
else
{
l = 1, r = k;
while (l<=r) //判断此时的a[i]和f数组中各个值大小关系,直到找到最优值
{
mid = (l + r) / 2;
if (a[i] > f[mid])
l = mid + 1;
else
r = mid - 1;
}
f[l] = a[i];
}
}
printf("%d\n",k);
} }
POJ - 3903 Stock Exchange(LIS最长上升子序列问题)的更多相关文章
- poj 3903 Stock Exchange(最长上升子序列,模版题)
题目 #include<stdio.h> //最长上升子序列 nlogn //入口参数:数组名+数组长度,类型不限,结构体类型可以通过重载运算符实现 //数组下标从1号开始. int bs ...
- {POJ}{3903}{Stock Exchange}{nlogn 最长上升子序列}
题意:求最长上升子序列,n=100000 思路:O(N^2)铁定超时啊....利用贪心的思想去找答案.利用栈,每次输入数据检查栈,二分查找替换掉最小比他大的数据,这样得到的栈就是更优的.这个题目确实不 ...
- POJ 3903 Stock Exchange 【最长上升子序列】模板题
<题目链接> 题目大意: 裸的DP最长上升子序列,给你一段序列,求其最长上升子序列的长度,n^2的dp朴素算法过不了,这里用的是nlogn的算法,用了二分查找. O(nlogn)算法 #i ...
- POJ3903 Stock Exchange LIS最长上升子序列
POJ3903 Stock Exchange #include <iostream> #include <cstdio> #include <vector> #in ...
- POJ 3903 Stock Exchange (E - LIS 最长上升子序列)
POJ 3903 Stock Exchange (E - LIS 最长上升子序列) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action ...
- LIS(nlogn) POJ 3903 Stock Exchange
题目传送门 题意:LIS最长递增子序列 O(nlogn) 分析:设当前最长递增子序列为len,考虑元素a[i]; 若d[len]<a[i],则len++,并使d[len]=a[i]; 否则,在d ...
- POJ 1887 Testingthe CATCHER (LIS:最长下降子序列)
POJ 1887Testingthe CATCHER (LIS:最长下降子序列) http://poj.org/problem?id=3903 题意: 给你一个长度为n (n<=200000) ...
- Poj 3903 Stock Exchange(LIS)
一.Description The world financial crisis is quite a subject. Some people are more relaxed while othe ...
- POJ 3903 Stock Exchange 最长上升子序列入门题
题目链接:http://poj.org/problem?id=3903 最长上升子序列入门题. 算法时间复杂度 O(n*logn) . 代码: #include <iostream> #i ...
随机推荐
- C# RAS 非对称加密类 支持长字符串
/// <summary> /// ikmb@163.com /// </summary> public class MyRAS { /// <summary> / ...
- bzoj 1602 [Usaco2008 Oct]牧场行走(LCA模板)
1602: [Usaco2008 Oct]牧场行走 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 379 Solved: 216[Submit][Sta ...
- SRM 391(1-250pt)
DIV1 250pt 题意:给两个'a'-'z'的字符串,是否存在一个'a'-'z'的置换,使得能将一个字符串转化成另一个字符串. 解法:题意即是求,s1和s2对应位置出现的字符在原字符串中出现的次数 ...
- legoblock秀上限
很久没有做题了,前天做了一道题结果弱的一逼...搜了解题报告不说...还尼玛秀了上限 题意: 给出宽和高为n和m的一堵墙,手上有长为1,2,3,4高均为1的砖,问形成一个坚固的墙有多少种做法. 坚固的 ...
- 缓存的概念(反向代理、CDN)
缓存在我们的日常开发中随处可见,理解缓存的概念,本质就是就近处理,比如很多热点数据,访问量很多,我们需要使用,就可以把它 缓存起来,然后下次访问就不用再去数据库的去查询了,而是直接使用缓存,现在说说大 ...
- Android Dialog透明度和暗度
1.设置透明度(Dialog自身的透明度)WindowManager.LayoutParams lp=dialog.getWindow().getAttributes(); lp.alpha=1.0f ...
- Amoeba for MySQL 非常好用的mysql集群软件
http://docs.hexnova.com/amoeba/ Amoeba for MySQL致力于MySQL的分布式数据库前端代理层,它主要在应用层访问MySQL的时候充当query 路由功能,专 ...
- 把安卓源代码中的system app独立出来,像开发普通app那样开发
个人建议首先依照android源码的ide/eclipse中的格式化xml和import导入到你编译的eclipse中,假设你编译的android源码是2.3以上的版本号的,建议用JDK6 ...
- iTunes 11.2更新下载:改善播客阅读
昨日,苹果公布了iTunes 11.2更新,新版别改善了播客阅读的方法,让用户能够在新的"未播映的"标签中疾速找到没有赏识的单集,其他功用包括主动删去现已播映的单集,并可在&quo ...
- ubuntu wine卸载程序并删除图标
卸载ubuntu 下用wine安装的程序,可以用wine uninstaller命令,打开 添加/删除程序界面,进行删除程序操作: