Bellovin

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 302    Accepted Submission(s): 148

Problem Description
Peter has a sequence a1,a2,...,an and he define a function on the sequence -- F(a1,a2,...,an)=(f1,f2,...,fn), where fi is the length of the longest increasing subsequence ending with ai.

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.

 
Input
There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases. For each test case:

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).

 
Output
For each test case, output n integers b1,b2,...,bn (1≤bi≤109) denoting the lexicographically smallest sequence.
 
Sample Input
3
1
10
5
5 4 3 2 1
3
1 3 5
 
Sample Output
1
1 1 1 1 1
1 2 3
 
题意:求以ai(0<i<n)结尾的最长上升子序列的个数.
题解:在LIS的O(n*log(n))的模板里面找到加一个dp数组记录每一位的最长上升子序列个数,顺序输出即可。
#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)的更多相关文章

  1. hdu 5748(LIS) Bellovin

    hdu 5748 Peter有一个序列a1,a2,...,ana_1,a_2,...,a_na​1​​,a​2​​,...,a​n​​. 定义F(a1,a2,...,an)=(f1,f2,...,fn ...

  2. hdu 5748(求解最长上升子序列的两种O(nlogn)姿势)

    Bellovin Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): Accepte ...

  3. Super Jumping! Jumping! Jumping!(hdu 1087 LIS变形)

    Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  4. HDU 1025 LIS二分优化

    题目链接: acm.hdu.edu.cn/showproblem.php?pid=1025 Constructing Roads In JGShining's Kingdom Time Limit: ...

  5. HDU 1950(LIS)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1950 Bridging signals Time Limit: 5000/1000 MS (Java ...

  6. hdu 1087(LIS变形)

    Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  7. hdu 1025 lis 注意细节!!!【dp】

    感觉这道题浪费了我半个小时的生命......哇靠!原来输出里面当len=1时是road否则是roads!!! 其实做过hdu 1950就会发现这俩其实一样,就是求最长上升子序列.我用结构体记录要连线的 ...

  8. HDU 1025 (LIS+二分) Constructing Roads In JGShining's Kingdom

    这是最大上升子序列的变形,可并没有LIS那么简单. 需要用到二分查找来优化. 看了别人的代码,给人一种虽不明但觉厉的赶脚 直接复制粘贴了,嘿嘿 原文链接: http://blog.csdn.net/i ...

  9. hdu 5256 LIS变形

    给一个数列,问最少修改多少个元素使数列严格递增.如果不是要求“严格”递增,那就是求最长不降子序列LIS,然后n-LIS就是答案.要严格递增也好办,输入的时候用每个数减去其下标处理一下就行了. /* * ...

随机推荐

  1. 【iOS开发】iOS开发CGRectGetMidX. CGRectGetMidY.CGRectGetMinY. CGRectGetMaxY. CGRectGetMinX. CGRectGetMaxX的使用

    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 110, 150)]; label.backgroundColor ...

  2. lintcode-57-三数之和

    57-三数之和 给出一个有n个整数的数组S,在S中找到三个整数a, b, c,找到所有使得a + b + c = 0的三元组. 注意事项 在三元组(a, b, c),要求a <= b <= ...

  3. MvcMusicStore学习中常出现的一个BUG

    BUG描述:var genreModel = storeDB.Genres.Include("Albums").Single(g => g.Name == genre); 前 ...

  4. linux安装mysql之设置远程访问权限

    1.将3306端口加入防火墙 /sbin/iptables -I INPUT -p tcp --dport 3306-j ACCEPT  #添加端口3306/etc/rc.d/init.d/iptab ...

  5. win7 Pthreads

    扩展地址 http://docs.php.net/manual/zh/book.pthreads.php 注意事项 php5.3或以上,且为线程安全版本.apache和php使用的编译器必须一致. 通 ...

  6. 入口文件-npm run dev

    如果你是用vue.js官网提供的脚手架工具并沿用默认配置的话,你执行npm run dev的时候会出来页面,是因为你根目录下的package.json文件里script配置了"dev&quo ...

  7. ob_flush()和flush()的区别

    最近写定时任务,遇到ob_flush()和flush()混淆的问题... ob_flush/flush在手册中的描述, 都是刷新输出缓冲区, 并且还需要配套使用, 所以会导致很多人迷惑- 其实, 他们 ...

  8. springboot 学习笔记(二)--- properties 配置

    springboot可以提供了多种方式配置properties. 一.Java System.setProperty(k, v) System.setProperty("myname&quo ...

  9. [洛谷P4124][CQOI2016]手机号码

    题目大意:给你两个$l,r$,求出$[l,r]$中符合要求的数,要求为至少有$3$个相邻的相同数字,且不可以同时出现$8$和$4$ 题解:数位$DP$ 卡点:无 C++ Code: #include ...

  10. [LOJ #2538][PKUWC 2018]Slay the Spire

    题目大意:一开始有 $2n$ 张牌,每张牌上都写着一个数字 $w_i$,有两种的牌,每种类型各 $n$ 张: 1.攻击牌:打出后对对方造成牌上的数字的伤害. 2.强化牌:打出后,设数字为 $x$,则其 ...