POJ 3903 Stock Exchange 最长上升子序列
来源:互联网 发布:新手淘宝开店教程 编辑:程序博客网 时间:2024/05/18 03:09
利用了二分的思想来找已经放进去的第一个比读入元素大的位置,然后替换一下就行,如果读入的数比头上的数目还大,那么更新头部,加入一个新的数,最后这个数组的大小就是最长的上升子序列了,复杂度大约nlogn,比传统的n2快了不少;
/*ID: sdj22251PROG: calfflacLANG: C++*/#include <iostream>#include <vector>#include <list>#include <map>#include <set>#include <deque>#include <queue>#include <stack>#include <bitset>#include <algorithm>#include <functional>#include <numeric>#include <utility>#include <sstream>#include <iomanip>#include <cstdio>#include <cmath>#include <cstdlib>#include <cctype>#include <string>#include <cstring>#include <cmath>#include <ctime>#define MAX 100000000#define LOCA#define PI acos(-1.0)using namespace std;int a[100001]; //记录数组int main(){#ifdef LOCAL freopen("ride.in","r",stdin); freopen("ride.out","w",stdout);#endif int n, m, cnt, high, low, mid, i; while(scanf("%d", &n) != EOF) { cnt = 0; //最长序列个数 for(i = 1; i <= n; i++) { scanf("%d", &m); if(cnt == 0 || m > a[cnt]) //如果是第一个或者比队头的大,则存入数组 a[++cnt] = m; else { high = cnt; low = 1; while(low <= high) //在已存序列中寻找位置,将输入的数替换进去,这样可以保证一直是上升序列 { mid = (low + high) / 2; if(a[mid] < m) low = mid + 1; else high = mid - 1; } a[low] = m; } } printf("%d\n", cnt); } return 0;}
- POJ 3903 Stock Exchange 最长上升子序列
- poj 3903 Stock Exchange (最长上升子序列)
- 证券交易所 Stock Exchange 最长上升子序列 poj 3903
- POJ 3903 Stock Exchange (LIS:最长上升子序列)
- poj 3903 Stock Exchange 最长上升子序列
- POJ 3903 —— Stock Exchange 最长上升子序列
- POJ 3903 Stock Exchange 最长上升子序列 模板题
- poj 3903 Stock Exchange(求最长上升子序列长度)
- Stock Exchange (POJ 3903) —— 最长上升子序列
- poj 3903 stock exchange 最长上升子序列(n*log(n))
- POJ 3903 Stock Exchange 最大上升子序列
- POJ3903 Stock Exchange 最长上升子序列DP]
- poj3903--Stock Exchange--nlogn贪心求最长上升子序列
- poj3903 Stock Exchange(最长上升子序列)
- POJ 3903-Stock Exchange/POJ 2533-Longest Ordered Subsequence(LIS-最长递增子序列长度)
- poj 3903-Stock Exchange最大上升子序(dp)
- poj 3903 最长上升子序列
- poj 3903(最长上升子序列 )
- OpenVPN协议解析-网络结构之外
- EHCache入门系列(三)–在Hibernate 中运用EHCache
- 类加载方式读取Java项目中的文件
- C++编程人员容易犯的10个C#错误
- zju 1671 Walking Ant (bfs 暴搜题)
- POJ 3903 Stock Exchange 最长上升子序列
- About the hashCode() Method
- 虚拟机VMware内的系统上网要注意的几点
- EHCache入门系列(四)–分布式缓存集群环境配置
- 将google reader里面的星标文章导成pdf
- TCP协议疑难杂症全景解析
- UBUNTU 命令学习
- 0.VC(ui)-hook-DrawItem挂掉
- 变换用户身份为root的方法su 与 sudo