Stock Exchange (最大上升子子串)
/*
题意:
给定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 (最大上升子子串)的更多相关文章
- POJ3903:Stock Exchange(LIS)
题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87125#problem/E 题目: Description The world ...
- POJ 3903 Stock Exchange
Stock Exchange Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2954 Accepted: 1082 De ...
- POJ 3903:Stock Exchange(裸LIS + 二分优化)
http://poj.org/problem?id=3903 Stock Exchange Time Limit: 1000MS Memory Limit: 65536K Total Submis ...
- POJ - 3903 Stock Exchange(LIS最长上升子序列问题)
E - LIS Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Descripti ...
- POJ 3903 Stock Exchange (E - LIS 最长上升子序列)
POJ 3903 Stock Exchange (E - LIS 最长上升子序列) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action ...
- poj3903 Stock Exchange(最长上升子序列)
转载请注明出处:http://blog.csdn.net/u012860063 题目链接:id=3903">http://poj.org/problem?id=3903 Descrip ...
- poj3903 Stock Exchange 二分+dp
题目地址:http://poj.org/problem?id=3903 题目: Description The world financial crisis is quite a subject. S ...
- Poj 3903 Stock Exchange(LIS)
一.Description The world financial crisis is quite a subject. Some people are more relaxed while othe ...
- POJ3903 Stock Exchange LIS最长上升子序列
POJ3903 Stock Exchange #include <iostream> #include <cstdio> #include <vector> #in ...
随机推荐
- web端自动化——python多线程
Python通过两个标准库thread和threading提供对线程的支持.thread提供了低级别的.原始的线程以及一个简单的锁.threading基于Java的线程模型设计. 锁(Lock)条件变 ...
- WXS---基础类库
- 理解Hybrid接口的应用
Hybrid接口既可以连接普通终端的接入链路又可以连接交换机间的干道链路,特允许多个vlan的帧通过,并可以在出接口方向将某些vlan帧的标签剥掉. 通过配置Hybrid接口,能过实现对VLAN标签的 ...
- python安装OpenCV – 4.1.0
(python3) [jiangshan@localhost ~]$ pip install opencv_python==4.1.0Collecting opencv_python==4.1.0 E ...
- java war包 远程debug出现的问题解决,学会查看日志
开启远程debug之后,8005 关闭tomcat 又启动不了了.. netstat -lnp 未发现8005接口 eclipse 内远程链接到服务器,debug 下发现服务器线程启动也存在问题.很多 ...
- netty-websocket简单的使用方法
最便捷使用netty-websocket方法 1.pom添加依赖 <dependency> <groupId>org.yeauty</groupId> <ar ...
- SpringBoot项目集成PageHelper使用
SpringBoot项目集成PageHelper使用 一.开始 地址:https://github.com/pagehelper/Mybatis-PageHelper 在spring boot ...
- 2、C语言实现通讯录
main函数入口: //test.c #include<stdio.h> #include<stdlib.h> #include<string.h> #includ ...
- hadoop 批量处理脚本编写
编写shell脚本就是解决批量处理 1. 在/usr/local/bin 创建脚本 并授权所有用户 chmod a+x xcall.sh xcall.sh 比如:删除/tmp/*所有文件 批量删 ...
- xml文件中引用网址报红色如何解决
用了ideal的宝宝们一定遇到过配置文件网址报红的错误吧 其实解决很简单,就是网不好导致它没法补全,我们手动给他补全就好啦 复制报红的网址 点击File==>settings==>lang ...