/*
题意:
给定L个整数A1,A2,...,An,按照从左到右的顺序选出尽量多的整数,
组成一个上升序列(子序列可以理解为:删除0个或者多个数,其他的数的吮吸不变)。
例如,1,6,2,3,7,5,可以选出上升子序列1,2,3,5,也可以选出1,6,7,
但前者更长,选出的上升子序列中相邻元素不能相等。
思路:
开辟一个栈,每次取栈顶元素s和读到的元素a做比较,如果a>s, 则加入栈;
如果a<s,则二分查找栈中的比a大的第1个数,并替换。 最后序列长度为栈的长度。
*/
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std; int a[]; int main()
{
int n,u,k;
while(cin>>n)
{
a[]=-;
k=;
for(int i=;i<n;i++)
{
cin>>u;
if(a[k]<u)
{
a[++k]=u;
}
else
{
int l=,r=k,mid;
while(l<=r)
{
mid=l+(r-l)/;
if(u>a[mid])
l=mid+;
else
r=mid-;
}
a[l]=u;
}
}
cout<<k<<endl;
}
}
 #include <stdio.h>
#include <string.h>
//author:YangSir
int a[];
int main(){
int n,i,max,b,num,x;
while(~scanf("%d",&n)){
num=;
a[]=-;
scanf("%d",&b);
a[]=max=b;
for(i=;i<n;i++){
scanf("%d",&b);//数组的每个值变化的过程就表示子串一个个代入
if(max<b){
max=b;
num++;
a[num]=max;//子串在增长
}
else{
x=num-;
while(a[x]>=b)
x--;
a[x+]=b;
}
max=a[num];//max可能会变
}
printf("%d\n",num);
}
return ;
}
 #include<stdio.h>
#include<algorithm>
using namespace std;
#define INF 1<<30
int main()
{
int n, a[], dp[]; while(~scanf("%d", &n))
{
for(int i=; i<n; i++)
{
scanf("%d", a+i);
dp[i] = INF;
}
for(int i=; i<n; i++)
*lower_bound(dp, dp+n, a[i]) = a[i];
printf("%d\n", lower_bound(dp, dp+n, INF)-dp);
}
return ;
}

Stock Exchange (最大上升子子串)的更多相关文章

  1. POJ3903:Stock Exchange(LIS)

    题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87125#problem/E 题目: Description The world ...

  2. POJ 3903 Stock Exchange

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

  3. POJ 3903:Stock Exchange(裸LIS + 二分优化)

    http://poj.org/problem?id=3903 Stock Exchange Time Limit: 1000MS   Memory Limit: 65536K Total Submis ...

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

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

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

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

  6. poj3903 Stock Exchange(最长上升子序列)

    转载请注明出处:http://blog.csdn.net/u012860063 题目链接:id=3903">http://poj.org/problem?id=3903 Descrip ...

  7. poj3903 Stock Exchange 二分+dp

    题目地址:http://poj.org/problem?id=3903 题目: Description The world financial crisis is quite a subject. S ...

  8. Poj 3903 Stock Exchange(LIS)

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

  9. POJ3903 Stock Exchange LIS最长上升子序列

    POJ3903 Stock Exchange #include <iostream> #include <cstdio> #include <vector> #in ...

随机推荐

  1. AWS 数据库(七)

    数据库概念 关系型数据库 关系数据库提供了一个通用接口,使用户可以使用使用 编写的命令或查询从数据库读取和写入数据. 关系数据库由一个或多个表格组成,表格由与电子表格相似的列和行组成. 以行列形式存储 ...

  2. beego框架(golang)学习验证码

    beego框架(golang)学习验证码 登录页面使用验证码 路由设置 /beego_admin_template/routers/router.go get请求页面, post验证用户名密码和验证码 ...

  3. 解决nginx端口占用问题

    1.键入命令:netstat -ano | findstr 80 查看80端口被哪个程序占用: 2.键入命令:netsh http show servicestate 查看http服务状态(注:解决后 ...

  4. RocketMQ控制台命令

    本文未完成,有空再补充,不小心发布了,抱歉 Rocket版本:4.3.0 这几天在整RocketMQ,可谓是困难重重,其中关于控制台的命令,网上的都是一半一半的, 所以我打算直接用整一个完整的官方的命 ...

  5. Django 之安全篇

    一.CSRF攻击 CSRF攻击概述: CSRF(Cross Site Request Forgery, 跨站域请求伪造)是一种网络的攻击方式,它在 2007 年曾被列为互联网 20 大安全隐患之一.其 ...

  6. 虚拟机中使用Samba实现文件共享

    首先我们给虚拟机安装samba服务(如果搭的是别的仓库记得开仓库) 输入命令:yum install samba samba服务的配置文件在,我们来看一下/etc/samba/smb.conf 输入命 ...

  7. Net Core 3 Mvc AliPay Demo

    AliPay - PC 钻研了几天的Webpack, 这几天回归了我的本行.Net, 跟随大佬的脚步, 开始做上了支付宝的支付. 创建项目 首先创建一基于.Net Core3.0的MVC项目, 然后引 ...

  8. php密码正则匹配

    <?php /** * @param $pwd * @return string */ function isPwd($pwd){ $pattern= '/^[0-9a-z_$]{6,16}$/ ...

  9. LeetCode 442. 数组中重复的数据(Find All Duplicates in an Array) 17

    442. 数组中重复的数据 442. Find All Duplicates in an Array 题目描述 Given an array of integers, 1 ≤ a[i] ≤ n (n ...

  10. 网络爬虫基本概念与Scrapy工具包使用

    Scrapy网络爬虫 Scrapy结构图: Scrapy流动图 图 2-1 1.在D:\Workspace下新建ScrapyTest文件夹,即D:\Workspace\ScrapyTest 2.cd ...