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. 修复在unix系统里的文件打开不能显示正常的颜色问题

    在mac上面看到mysql的配置文件的颜色永远是白色,为了让配置文件的颜色更加分明些,这个时候只需进入到home目录下新建一个.vimrc文件, vim  .vimrc set nu syntax o ...

  2. eclipse各种操作指南

    一.设置代码自动补全 1.设置java代码自动补全 Auto activation delay(ms):0 Auto activation trigger for java : .abcdefghij ...

  3. HDU 3359 高斯消元模板题,

    http://acm.hdu.edu.cn/showproblem.php?pid=3359 题目的意思是,由矩阵A生成矩阵B的方法是: 以a[i][j]为中心的,哈曼顿距离不大于dis的数字的总和 ...

  4. Crusher Django 学习笔记3 学习使用模板系统

    http://crusher-milling.blogspot.com/2013/09/crusher-django-tutorial3-using-template.html 顺便学习一下 goag ...

  5. 物体检测丨Faster R-CNN详解

    这篇文章把Faster R-CNN的原理和实现阐述得非常清楚,于是我在读的时候顺便把他翻译成了中文,如果有错误的地方请大家指出. 原文:http://www.telesens.co/2018/03/1 ...

  6. CocoaPods 提交自己的库

    今想把自己写的一个view提交到CocoaPods时候,突然发现pull request被拒了,原来从去年开始就改用trunk了... 网上那些folk 在提交的pull request的教程都不可用 ...

  7. 如何在cmd中运行PHP

    我的php安装目录在 d:\php 那么 运行 cmd >d: >cd php 要让工作目录指向php.exe的安装文件夹 然后就可以用php指令了 比如 在该文件夹下面新建一个test. ...

  8. 后端 node 项目工具集

    后端 node 项目工具集 editor vs code webstorm 质量检查 eslint prettier 命令行相关 better-run-npm npm-run-all nodemon ...

  9. springCloud当中Eureca sever当中Camden到底是什么?

    [学习笔记] 做个普通的maven project,quickstart archetype.改成jdk.8.下面Camden.SR1是版本名,springcloud的版本名称很奇特,它是按照伦敦地铁 ...

  10. 读懂《HTML5网页开发实例详解》这本书

    你还在用Flash嘛?帮主早不用了 乔布斯生前在公开信<Flash之我见>中预言:像HTML 5这样在移动时代中创立的新标准,将会在移动设备上获得胜利. ——国际巨头Google.苹果等都 ...