<题目链接>

题目大意:

裸的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 【最长上升子序列】模板题的更多相关文章

  1. POJ 3903 Stock Exchange 最长上升子序列入门题

    题目链接:http://poj.org/problem?id=3903 最长上升子序列入门题. 算法时间复杂度 O(n*logn) . 代码: #include <iostream> #i ...

  2. POJ 3903 Stock Exchange (E - LIS 最长上升子序列)

    POJ 3903    Stock Exchange  (E - LIS 最长上升子序列) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action ...

  3. POJ - 3903 Stock Exchange(LIS最长上升子序列问题)

    E - LIS Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u   Descripti ...

  4. {POJ}{3903}{Stock Exchange}{nlogn 最长上升子序列}

    题意:求最长上升子序列,n=100000 思路:O(N^2)铁定超时啊....利用贪心的思想去找答案.利用栈,每次输入数据检查栈,二分查找替换掉最小比他大的数据,这样得到的栈就是更优的.这个题目确实不 ...

  5. poj 3903 Stock Exchange(最长上升子序列,模版题)

    题目 #include<stdio.h> //最长上升子序列 nlogn //入口参数:数组名+数组长度,类型不限,结构体类型可以通过重载运算符实现 //数组下标从1号开始. int bs ...

  6. POJ 3903 Stock Exchange

    Stock Exchange Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2954   Accepted: 1082 De ...

  7. Poj 3903 Stock Exchange(LIS)

    一.Description The world financial crisis is quite a subject. Some people are more relaxed while othe ...

  8. LIS(nlogn) POJ 3903 Stock Exchange

    题目传送门 题意:LIS最长递增子序列 O(nlogn) 分析:设当前最长递增子序列为len,考虑元素a[i]; 若d[len]<a[i],则len++,并使d[len]=a[i]; 否则,在d ...

  9. POJ-1458(LCS:最长公共子序列模板题)

    Common Subsequence POJ-1458 //最长公共子序列问题 #include<iostream> #include<algorithm> #include& ...

随机推荐

  1. String split方法与Guava Splitter用法区别

    String split方法与Guava Splitter用法区别 今天同事写了一段使用String split方法的代码,如下所示,同事期望得到的是字符"1",但是没想到却得到空 ...

  2. C#基础系列-反射

    1.反射的定义 反射(Reflection),是.Net中获取运行时类型信息的方式.程序集中有关程序及其类型的数据被称为元数据(metadata).程序在运行时,可以查看其它程序集或其本身的元数据.一 ...

  3. TERMIOS详解【转】

    转自:https://blog.csdn.net/guo_wangwei/article/details/1102931# TERMIOS NAME termios, tcgetattr, tcset ...

  4. Linux下rsyslog日志收集服务环境部署记录【转】

    rsyslog 可以理解为多线程增强版的syslog. 在syslog的基础上扩展了很多其他功能,如数据库支持(MySQL.PostgreSQL.Oracle等).日志内容筛选.定义日志格式模板等.目 ...

  5. discuz安装:mysqli_connect()不支持advice_mysqli_connect

    原文:http://blog.csdn.net/changzhi1990/article/details/40983247 php -m 输出: PHP Warning: PHP Startup: U ...

  6. MariaDB:删除数据库报错:error: 'Error dropping database (can't rmdir './shiro', errno: 39)'

    今天在删除一个库的时候报错,如下图所示. 删除命名:mysqladmin –u root –p  drop shiro 解决办法: 删除./shiro目录下面的所有文件和目录. 重新执行删除命令即可!

  7. Mac安装Homebrew记录

    在终端输入: ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install) ...

  8. Java中的钩子方法

    钩子方法是啥 钩子顾名思义就是用来挂东西的.那么要挂东西必须有个被挂的东西,要不就是铁环.要不就是墙的边沿.所以要能挂住东西必须要有个被勾住的铁环,要一个钩子.那么在java中也是同样的原理,你首先需 ...

  9. ubuntu chrome 安装ubuntu16.04 : google浏览器安装及离线插件安装(谷歌访问助手)

    1.https://blog.csdn.net/cheneykl/article/details/79187954 https://download.oracle.com/otn-pub/java/j ...

  10. web----WSGI

    概念: WSGI协议其实是定义了一种server与application解耦的规范 WSGI规范简单理解:一方面给Server提供接口,凡是以这种接口的web服务器,都是遵循WSGI规范的 另一方面给 ...