poj 3903 stock exchange 最长上升子序列(n*log(n))
来源:互联网 发布:2017中国十大网络主播 编辑:程序博客网 时间:2024/05/17 22:24
题目连接:http://poj.org/problem?id=3903
题意:求最长上升子序列,n=100000
思路:动态方程 d【i】=max(d【j】+1,【i】)(1<=j<i,a[i]>a[j]),此方法在此行不通,timelimited(O(n*n))。
假设序列为a【0】,a【1】.......,如果i<j,d[i]=d[j]===>a[i]>a[j],但我们只需保存序列长度的为d【i】的最小值a【j】,于是 我们在加一个数组s【i】,代表序列长度的i的最小值(是给定序列里面的值),可以知道s【1】<s【2】<s【3】<...... 。 对于每个a【i】,我们就可利用二分查找,找到最大的长度L,满足s【L】<=a【i】,于是就有
d【i】=L,在更新s【】的值,使其最小。
#include<stdio.h>#include<algorithm>using namespace std;int a[100010];int s[100010];int d[100010];int main(){int i,j,k,n,m,pos;while(scanf("%d",&n)!=EOF){for(i=0;i<n;i++)scanf("%d",&a[i]);//s[0]=a[0];//pos=1;for(i=1;i<=n;i++)s[i]=100010;for(i=0;i<n;i++){k=lower_bound(s+1,s+n,a[i])-(s);//if(k==pos)//pos++;d[i]=k;s[k]=a[i];}pos=-1;for(i=0;i<n;i++){pos=max(pos,d[i]);}printf("%d\n",pos);}}
0 0
- poj 3903 stock exchange 最长上升子序列(n*log(n))
- Stock Exchange+POJ+最长升子序列n*log(n)算法
- poj 1836 Alignment (最长上升子序列 N*log(n))@
- 最长上升子序列n log n
- poj 3903 Stock Exchange(求最长上升子序列长度)
- Stock Exchange (POJ 3903) —— 最长上升子序列
- 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 最长上升子序列 模板题
- poj3903 Stock Exchange(最长上升子序列)
- 【最长上升子序列 - (n^2)】
- 【最长上升子序列nlog(n)】
- n log n 的最长上升子序列
- n log n的最长上升子序列
- 系统安全日志的注意事项
- 为什么监听不到开机广播action.BOOT_COMPLETED
- Linux开发环境搭建与使用——Linux系统( ubuntu )安装方案
- cocos2dx 坐标系 自己要理解
- linux(centos7)下安装 scala2.11.6
- poj 3903 stock exchange 最长上升子序列(n*log(n))
- CSS和JS标签style属性对照表
- Surrounded Regions
- 利用IDA Pro反编译破解.exe
- local_irq_disable
- 安卓框架图
- 渐透明效果
- Nike慢跑鞋 stbc qgqz qeky
- java内在泄漏