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. 爬虫的UA池和代理池

    爬虫的UA池和代理池   一.下载中间件 先祭出框架图: 下载中间件(Downloader Middlewares) 位于scrapy引擎和下载器之间的一层组件. - 作用: (1)引擎将请求传递给下 ...

  2. 2017"百度之星"程序设计大赛 - 资格赛 寻找母串

    Problem Description 对于一个串S,当它同时满足如下条件时,它就是一个01偏串: 1.只由0和1两种符组成: 2.在S的每一个前缀中,0的个数不超过1的个数: 3.S中0的个数和1的 ...

  3. python入门之正则表达式

    正则 通过re模块实现 eg:>>>import re        >>>re.findall('abc',str_name) 在strname里面完全匹配字符串 ...

  4. 2个rman自动恢复的脚本

    ### scripts 1--the scirpt is used for restore db from vcs to a point to time recovery--and the targe ...

  5. Chess 模拟

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=6114 Problem Description 車是中国象棋中的一种棋子,它能攻击同一行或同一列中没有其他棋 ...

  6. equals方法那些事

    1.Equals 很多人对equals方法的用法有些模糊,这里来为大家梳理下: 字符串中的equals方法,该方法用来判断两个字符串的内容是否相同. 例1: String str1="Hel ...

  7. react注意点

    event 对象 和普通浏览器一样,事件监听函数会被自动传入一个 event 对象,这个对象和普通的浏览器 event 对象所包含的方法和属性都基本一致.不同的是 React.js 中的 event  ...

  8. ubuntu 14.04 安装tomcat服务器 配置图片路径和文件路径

    root@hett-PowerEdge-T30:/usr/local/src# lltotal 235956drwxr-xr-x  6 root root      4096  3月 26 14:48 ...

  9. cookie安全

    www.baidu.com host 文件 定义 a.baidu.com 为127.0.01 本地编写php程序 读取浏览器发送给 a.baidu.com的cookie 会把 .baidu.com域下 ...

  10. OpenRead方法打开文件并读取

    实现效果: 知识运用: File类的OpenRead方法 //实现打开现有文件以进行读取 public static FileStream OpenRead(string path) FileStre ...