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 ...
随机推荐
- Python爬虫-爬取豆瓣图书Top250
豆瓣网站很人性化,对于新手爬虫比较友好,没有如果调低爬取频率,不用担心会被封 IP.但也不要太频繁爬取. 涉及知识点:requests.html.xpath.csv 一.准备工作 需要安装reques ...
- SecureCRT配色方案(转)
1. 设置背景颜色和字体颜色: 选项(Options)==>会话选项(Sessions options)==>终端(Terminal)==>仿真(Emulation) 选项(Opt ...
- SSH无密码(密钥验证)登录的配置
进入到我的home目录 cd ~/.ssh [root@shtppATTSTPUBv03 home]# cd ~/.ssh [root@shtppATTSTPUBv03 .ssh]# pwd /roo ...
- LeetCode 242. 有效的字母异位词(Valid Anagram)
242. 有效的字母异位词 LeetCode242. Valid Anagram 题目描述 给定两个字符串 s 和 t ,编写一个函数来判断 t 是否是 s 的一个字母异位词. 示例 1: 输入: s ...
- Logstash配置安装
logstash配置 http.host: xpack.monitoring.enabled: true xpack.monitoring.elasticsearch.username:"l ...
- 开始使用 Manjaro(添加源+字体渲染去模糊+软件安装+优化配置+常见错误)(30)
1. 添加 archlinux 镜像源 1. 步骤一 向 /etc/pacman.d/mirrorlist 中添加国内镜像地址 1.1 方法1:自动添加 1. 输入如下命令查看国内镜像源,并按质量排序 ...
- QT 读写.ini配置文件
当需要存放的数据量较少时合适使用.ini配置文件. #include <QCoreApplication> #include <QSettings> void SystemSe ...
- Ajax跨越请求失败,解决
跨越请求 1.1什么是跨域(两个不同系统之间的访问.调用) (1)域名不同,即两个不同的应用. (2)域名相同,但是端口不同,即同一个应用中的不同子系统. 1.2 Ajax跨域请求的缺陷 (1)创建t ...
- PowerShell自动部署ASP.NET Core程序到 IIS
Windows PowerShell 是一种命令行外壳程序和脚本环境,使命令行用户和脚本编写者可以利用 .NET Framework的强大功能.有关于更多PowerShell的信息,可参阅百度词条 接 ...
- Java中@SuppressWarnings("unchecked")的作用
J2SE 提供的最后一个批注是 @SuppressWarnings.该批注的作用是给编译器一条指令,告诉它对被批注的代码元素内部的某些警告保持静默. 一点背景:J2SE 5.0 为 Java 语言增加 ...