POJ 3903 Stock Exchange 【最长上升子序列】模板题
<题目链接>
题目大意:
裸的DP最长上升子序列,给你一段序列,求其最长上升子序列的长度,n^2的dp朴素算法过不了,这里用的是nlogn的算法,用了二分查找。
O(nlogn)算法
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; const int N= 1e5+;
int a[N],rise[N]; int main(){
int n;while(~scanf("%d",&n)){
memset(rise,,sizeof(rise));
for(int i=;i<n;i++)scanf("%d",&a[i]);
int len=;
rise[]=-1e9;
for(int i=;i<n;i++){
if(a[i]>rise[len])rise[++len]=a[i];
else{
int j=lower_bound(rise+,rise++len,a[i])-rise;
rise[j]=a[i];
}
}
printf("%d\n",len);
}
}
虽然(n^2)算法过不了此题,但是还是先记录下
#include<cstdio>
int main()
{
int i, j, n;
int dp[], a[];
while (scanf("%d", &n) != EOF)
{
int max = ;
for (i = ; i<n; i++)
scanf("%d", &a[i]);
dp[] = ;
for (i = ; i<n; i++)
{
dp[i] = ;
for (j = ; j<i; j++)
if (a[j]<a[i] && dp[j] + >dp[i])
dp[i] = dp[j] + ;
}
for (i = ; i<n; i++)
if (max<dp[i])
max = dp[i];
printf("%d\n", max);
}
}
POJ 3903 Stock Exchange 【最长上升子序列】模板题的更多相关文章
- POJ 3903 Stock Exchange 最长上升子序列入门题
题目链接:http://poj.org/problem?id=3903 最长上升子序列入门题. 算法时间复杂度 O(n*logn) . 代码: #include <iostream> #i ...
- POJ 3903 Stock Exchange (E - LIS 最长上升子序列)
POJ 3903 Stock Exchange (E - LIS 最长上升子序列) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action ...
- POJ - 3903 Stock Exchange(LIS最长上升子序列问题)
E - LIS Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Descripti ...
- {POJ}{3903}{Stock Exchange}{nlogn 最长上升子序列}
题意:求最长上升子序列,n=100000 思路:O(N^2)铁定超时啊....利用贪心的思想去找答案.利用栈,每次输入数据检查栈,二分查找替换掉最小比他大的数据,这样得到的栈就是更优的.这个题目确实不 ...
- poj 3903 Stock Exchange(最长上升子序列,模版题)
题目 #include<stdio.h> //最长上升子序列 nlogn //入口参数:数组名+数组长度,类型不限,结构体类型可以通过重载运算符实现 //数组下标从1号开始. int bs ...
- POJ 3903 Stock Exchange
Stock Exchange Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2954 Accepted: 1082 De ...
- Poj 3903 Stock Exchange(LIS)
一.Description The world financial crisis is quite a subject. Some people are more relaxed while othe ...
- LIS(nlogn) POJ 3903 Stock Exchange
题目传送门 题意:LIS最长递增子序列 O(nlogn) 分析:设当前最长递增子序列为len,考虑元素a[i]; 若d[len]<a[i],则len++,并使d[len]=a[i]; 否则,在d ...
- POJ-1458(LCS:最长公共子序列模板题)
Common Subsequence POJ-1458 //最长公共子序列问题 #include<iostream> #include<algorithm> #include& ...
随机推荐
- spoj gss1 gss3
传送门 gss1 gss3 spoj gss系列=最大字段和套餐 gss1就是gss3的无单点修改版 有区间查询和单点修改,考虑用线段树维护 我们要维护区间权值和\(s\),区间最大前缀和\(xl\) ...
- python - 数据描述符(class 内置 get/set/delete方法 )
数据描述符(class 内置 get/set/del方法 ): # 什么是描述符 # 官方的定义:描述符是一种具有“捆绑行为”的对象属性.访问(获取.设置和删除)它的属性时,实际是调用特殊的方法(_g ...
- Django学习手册 - cookie / session
cookie """ cookie属性: obj.set_cookie(key,value,....) obj.set_signed_cookie(key,value,s ...
- IMU 预积分推导
给 StereoDSO 加 IMU,想直接用 OKVIS 的代码,但是有点看不懂.知乎上郑帆写的文章<四元数矩阵与 so(3) 左右雅可比>提到 OKVIS 的预积分是使用四元数,而预积分 ...
- pl/sql Devloper 关键字转为大写
英文版: peferences-editor-keyword case -uppercase 中文版:
- springboot学习笔记-6 springboot整合RabbitMQ
一 RabbitMQ的介绍 RabbitMQ是消息中间件的一种,消息中间件即分布式系统中完成消息的发送和接收的基础软件.这些软件有很多,包括ActiveMQ(apache公司的),RocketMQ(阿 ...
- java中网络设置代理
三种方式: 1.JVM启动时加参数设置代理 在系统启动时,使用-D项来设置代理. 例如: java -Dhttp.ProxyHost="proxyUrl" -Dhttp.Proxy ...
- 文件&报表状态ID
def_filestatus Uploading=4 WaitingParse=6 Parsing=10 Completed=14 ParseError=1006 UploadError=1004 d ...
- Linux MMC framework2:基本组件之core
1.前言 本文主要core组件的主要流程,在介绍的过程中,将详细说明和core相关的流程,涉及到其它组件的详细流程再在相关文章中说明. 2.主要数据结构和API TODO 3. 主要流程 3.1 mm ...
- C# 关于用7zip压缩文件提示win32exception 系统找不到文件解决方案(win7 x64)
网上已经很多这方面的资料了,我就简单的说下好了 为了方便以后的查看 --------------------- 1.需要下载7zSharp:http://7zsharp.codeplex.com/re ...