Description

Peter has a sequence  and he define a function on the sequence -- , where  is the length of the longest increasing subsequence ending with .

Peter would like to find another sequence  in such a manner that  equals to . Among all the possible sequences consisting of only positive integers, Peter wants the lexicographically smallest one.

The sequence  is lexicographically smaller than sequence , if there is such number  from  to , that  for  and .

Input

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

The first contains an integer   -- the length of the sequence. The second line contains  integers  .

Output

For each test case, output  integers   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 英语题目很难度,但是题意很简单,给你一个整数序列,输出以每个数结尾的最长上升子序列的长度。
 #include<cstdio>
#include<algorithm>
#define INF 0x3f3f3f3f
using namespace std;
int dp[];
int a[];
int b[];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,i,j;
scanf("%d",&n);
for(i = ; i <= n ; i++)
{
scanf("%d",&a[i]);
dp[i]=;
b[i]=INF;
}
for(i = ; i <= n ; i++)
{
int k=lower_bound(b+,b+n+,a[i])-b; //函数返回值为大于a[i]的第一个值的位置,比如序列1 1 4 5,a[i]为2,返回值为3
dp[i]=k; //与二分法类似,将数放入新数组
b[k]=a[i];
}
for(i = ; i < n ; i++)
printf("%d ",dp[i]);
printf("%d\n",dp[n]);
}
}

杭电 5748 Bellovin的更多相关文章

  1. acm入门 杭电1001题 有关溢出的考虑

    最近在尝试做acm试题,刚刚是1001题就把我困住了,这是题目: Problem Description In this problem, your task is to calculate SUM( ...

  2. 杭电acm 1002 大数模板(一)

    从杭电第一题开始A,发现做到1002就不会了,经过几天时间终于A出来了,顺便整理了一下关于大数的东西 其实这是刘汝佳老师在<算法竞赛 经典入门 第二版> 中所讲的模板,代码原封不动写上的, ...

  3. 杭电OJ——1198 Farm Irrigation (并查集)

    畅通工程 Problem Description 某省调查城镇交通状况,得到现有城镇道路统计表,表中列出了每条道路直接连通的城镇.省政府"畅通工程"的目标是使全省任何两个城镇间都可 ...

  4. 杭电ACM分类

    杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...

  5. 高手看了,感觉惨不忍睹——关于“【ACM】杭电ACM题一直WA求高手看看代码”

    按 被中科大软件学院二年级研究生 HCOONa 骂为“误人子弟”之后(见:<中科大的那位,敢更不要脸点么?> ),继续“误人子弟”. 问题: 题目:(感谢 王爱学志 网友对题目给出的翻译) ...

  6. C#利用POST实现杭电oj的AC自动机器人,AC率高达50%~~

    暑假集训虽然很快乐,偶尔也会比较枯燥,,这个时候就需要自娱自乐... 然后看hdu的排行榜发现,除了一些是虚拟测评机的账号以外,有几个都是AC自动机器人 然后发现有一位作者是用网页填表然后按钮模拟,, ...

  7. 杭电ACM2076--夹角有多大(题目已修改,注意读题)

    杭电ACM2076--夹角有多大(题目已修改,注意读题) http://acm.hdu.edu.cn/showproblem.php?pid=2076 思路很简单.直接贴代码.过程分析有点耗时间. / ...

  8. 杭电ACM2092--整数解

    杭电ACM2092--整数解    分析 http://acm.hdu.edu.cn/showproblem.php?pid=2092 一个YES,一个Yes.试了10几次..我也是无语了..哪里都不 ...

  9. 杭电2034——人见人爱A-B

    #include <stdio.h> #include <algorithm> using namespace std; int main () { int a[110],b[ ...

随机推荐

  1. 最大xor,and,or

    http://210.33.19.103/contest/998 and,or部分 并不用01trie,题目&题解:https://blog.csdn.net/dreaming__ldx/ar ...

  2. Sawgger框架

    简介详情:https://blog.csdn.net/sanyaoxu_2/article/details/80555328

  3. 111 Minimum Depth of Binary Tree 二叉树的最小深度

    给定一个二叉树,找出其最小深度.最小深度是从根节点到最近叶节点的最短路径的节点数量.详见:https://leetcode.com/problems/minimum-depth-of-binary-t ...

  4. C8051F_CAN

    CAN总线特点:基于报文编码而非对节点编码,增删节点对系统没有影响,靠干扰稳定性好,速率高. 小工具:CANtool 收发器:CAN总线收发器CTM1050,通信速率1Mbps,至少可连接110个节点 ...

  5. Navicat for MySQL在ubuntu下运行没有反应

    Step1: 打开Navicat官网,下载Navicat ,网址:http://www.navicat.com/en/download/download.html Step2:进入下载目录,解压压缩包 ...

  6. codewars遇到的比较有意思的题目

    题目要求是编写一个函数用来检测一个字符串,字符串是一系列单词组成,每个单词间用空格隔开,不用考虑空字符串的情况,返回长度最小的那个单词的长度. 博主刚入门PHP,技术还很菜,没有想出来,看了其他人的解 ...

  7. Spring Boot :Druid Monitor

    忙里偷个闲,在这里分享一下SpringBoot集成Druid实现数据库监控功能,有什么错误欢迎大家指出! 参考文件: Spring实现Druid监控:https://www.cnblogs.com/w ...

  8. 不同版本的 Tomcat 设置用户名密码 的方法

    Tomcat : tomcat根目录\conf\tomcat-users.xml,找到 <tomcat-users> 标签,在后面添加 <user username="ad ...

  9. Android学习总结(三)——IntentService的用法

    一.IntentService的基本概念 IntentService是继承于Service并处理异步请求的一个类,在IntentService内有一个工作线程来处理耗时操作,启动IntentServi ...

  10. UVA 753 A Plug for UNIX (最大流)

    关键在建图,转换器连一条容量无限的边表示可以转化无数次,设备的插头连源点,插座连汇点. dinic手敲已熟练,输出格式又被坑,总结一下,输出空行多case的,一个换行是必要的,最后一个不加空行,有Te ...