hdu 5748(LIS)
Bellovin
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 302 Accepted Submission(s): 148
Peter would like to find another sequence b1,b2,...,bn in such a manner that F(a1,a2,...,an) equals to F(b1,b2,...,bn). Among all the possible sequences consisting of only positive integers, Peter wants the lexicographically smallest one.
The sequence a1,a2,...,an is lexicographically smaller than sequence b1,b2,...,bn, if there is such number i from 1 to n, that ak=bk for 1≤k<i and ai<bi.
The first contains an integer n (1≤n≤100000) -- the length of the sequence. The second line contains n integers a1,a2,...,an (1≤ai≤109).
1
10
5
5 4 3 2 1
3
1 3 5
1 1 1 1 1
1 2 3
#include<iostream>
#include<cstdio>
#include<cstring>
#include <algorithm>
using namespace std;
const int N = ;
int a[N];
int dp[N],c[N]; int main()
{
int tcase;
scanf("%d",&tcase);
while(tcase--)
{
int n;
scanf("%d",&n);
for(int i=; i<=n; i++)
{
scanf("%d",&a[i]);
}
int MAX = ,j=;
c[] = a[];
dp[] = ;
for(int i=; i<=n; i++)
{
if(a[i]<=c[]) j = ;
else if(a[i]>c[MAX]) j = ++MAX;
else j = lower_bound(c+,c++MAX,a[i])-c;
c[j] = a[i];
dp[i] = j;
}
for(int i=; i<n; i++)
{
printf("%d ",dp[i]);
}
printf("%d\n",dp[n]);
}
return ;
}
hdu 5748(LIS)的更多相关文章
- hdu 5748(LIS) Bellovin
hdu 5748 Peter有一个序列a1,a2,...,ana_1,a_2,...,a_na1,a2,...,an. 定义F(a1,a2,...,an)=(f1,f2,...,fn ...
- hdu 5748(求解最长上升子序列的两种O(nlogn)姿势)
Bellovin Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): Accepte ...
- Super Jumping! Jumping! Jumping!(hdu 1087 LIS变形)
Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- HDU 1025 LIS二分优化
题目链接: acm.hdu.edu.cn/showproblem.php?pid=1025 Constructing Roads In JGShining's Kingdom Time Limit: ...
- HDU 1950(LIS)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1950 Bridging signals Time Limit: 5000/1000 MS (Java ...
- hdu 1087(LIS变形)
Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- hdu 1025 lis 注意细节!!!【dp】
感觉这道题浪费了我半个小时的生命......哇靠!原来输出里面当len=1时是road否则是roads!!! 其实做过hdu 1950就会发现这俩其实一样,就是求最长上升子序列.我用结构体记录要连线的 ...
- HDU 1025 (LIS+二分) Constructing Roads In JGShining's Kingdom
这是最大上升子序列的变形,可并没有LIS那么简单. 需要用到二分查找来优化. 看了别人的代码,给人一种虽不明但觉厉的赶脚 直接复制粘贴了,嘿嘿 原文链接: http://blog.csdn.net/i ...
- hdu 5256 LIS变形
给一个数列,问最少修改多少个元素使数列严格递增.如果不是要求“严格”递增,那就是求最长不降子序列LIS,然后n-LIS就是答案.要严格递增也好办,输入的时候用每个数减去其下标处理一下就行了. /* * ...
随机推荐
- [Elasticsearch] 多字段搜索 (六) - 自定义_all字段,跨域查询及精确值字段
自定义_all字段 在元数据:_all字段中,我们解释了特殊的_all字段会将其它所有字段中的值作为一个大字符串进行索引.尽管将所有字段的值作为一个字段进行索引并不是非常灵活.如果有一个自定义的_al ...
- 【Python】- 如何使用Visual Studio 2013编写python?
安装Visual Studio 2013 1.VS2013下载安装略 安装python2.7 1.从官网下载python2.7,下载地址:https://www.python.org/getit/ ...
- arcgis的炸开多边形功能
有时候我们使用dissolve工具,或其他操作会将空间不相连的多边形对应的属性合并到一起,如图: 在高级编辑工具中: 有这样一个工具,但是它能满足我的要求,但是他不是批量的,不过它使用起来比较方便. ...
- zTree基本功能[core]
zTree 是一个依靠jQuery实现的多功能"树插件".优异的性能.灵活的配置.多种功能的组合是 zTree 最大优点. zTree v3.0 将核心代码按照功能进行了分割,不需 ...
- 排查nginx、tomcat内存和服务器负载之后
最近客户现在提出系统访问非常慢,需要优化提升访问速度,在排查了nginx.tomcat内存和服务器负载之后,判断是数据库查询速度慢,进一步排查发现是因为部分视图和表查询特别慢导致了整个系统的响应时间特 ...
- 移动开发:美团外卖Android Lint代码检查实践
概述 Lint是Google提供的Android静态代码检查工具,可以扫描并发现代码中潜在的问题,提醒开发人员及早修正,提高代码质量.除了Android原生提供的几百个Lint规则,还可以开发自定义L ...
- 深入研究JavaScript的事件机制
本篇开始将回顾下Javascript的事件机制.同时会从一个最小的函数开始写到最后一个具有完整功能的,强大的事件模块.为叙述方便将响应函数/回调函数/事件Listener/事件handler都称为事件 ...
- PowerMock
EasyMock 以及 Mockito 都因为可以极大地简化单元测试的书写过程而被许多人应用在自己的工作中,但是这 2 种 Mock 工具都不可以实现对静态函数.构造函数.私有函数.Final 函数以 ...
- JAX-WS 注解
一.概述 “基于 XML 的 Web Service 的 Java API”(JAX-WS)通过使用注释来指定与 Web Service 实现相关联的元数据以及简化 Web Service 的开发.注 ...
- c++ 公有继承的赋值兼容规则
赋值兼容规则是指在需要基类对象的任何地方都可以使用公有派生类的对象来替代.通过公有继承,派生类得到了基类中除构造函数.析构函数之外的所有成员,而且所有成员的访问控制属性也和基类完全相同.这样,公有派生 ...