HDU-5748 Bellovin 【LIS(STL应用)】
来源:互联网 发布:药水哥网络臭要饭的 编辑:程序博客网 时间:2024/05/21 06:39
E - Bellovin
Time Limit:3000MS Memory Limit:131072KB 64bit IO Format:%I64d & %I64u
Submit
Status
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
- 题意:给定序列a1,a2,a2…..aN,f(a i)代表以a i为结尾元素的最大上升子序列长度,让你求出一个序列b1,b2….bN,使任意的f(a i)=f(b i),求出满足要求的最小序列并输出(b i>1,从前向后贪心满足最小的);
- 思路:要输出最小的,那第一个肯定是1,第二个就要看f(a2),如果f(a2)=1那么第二个肯定选1,如果不成立,那么为2,以此类推可以知道bi=f(bi)=f(ai),就是求出每一位的最长上升子序列的长度;
- 失误:用vector写不知道哪错了,指针一直不对,调试好久也找不出来,最后一急把代码调试的一删,没想到就对了,错误还能这样找;
- 代码如下:
#include<cstdio>#include<vector>using namespace std;int main(){ int T,N,i,tem; scanf("%d",&T); while(T--) { scanf("%d",&N); scanf("%d",&tem); vector<int> VEC,ord; vector<int>::iterator iter; VEC.push_back(tem); ord.push_back(1); for(i=2;i<=N;++i) { scanf("%d",&tem); iter = lower_bound(VEC.begin(),VEC.end(),tem); ord.push_back( (iter-VEC.begin())+1);//用队列可能会更方便 if(iter==VEC.end()) VEC.push_back(tem); else *iter = tem; } int k=0; for(iter=ord.begin();iter!=ord.end();++iter) { if(k!=0) printf(" "); k=1; printf("%d",*iter); } printf("\n"); } return 0;}
- HDU-5748 Bellovin 【LIS(STL应用)】
- hdu 5748 Bellovin(LIS)
- HDU 5748 (Bellovin LIS)
- HDU 5748 Bellovin(LIS)
- 【HDU】5748 - Bellovin(LIS)
- HDU 5748 Bellovin(LIS)
- HDU 5748 Bellovin (LIS)
- LIS hdu 5748 (Bellovin)
- HDU-5748-Bellovin【LIS】
- 【HDU】-5748-Bellovin(LIS,变化)
- HDU:5748 Bellovin(LIS+打表)
- HDU 5748 Bellovin(LIS nlogn)
- HDU Problem 5748 Bellovin 【LIS】
- Bellovin【hdu 5748 dp lis】
- HDOJ 5748 Bellovin(LIS)
- HDOJ-----5748Bellovin(LIS)
- HDU 5748 BestCoder Round #84 Bellovin (LIS)(树状数组)
- hdu5748 Bellovin(LIS模板)
- 浅析Java中的final关键字
- 《VR入门系列教程》之4---运行平台
- tyvj 1066 合并果子(优先队列)
- 阅读小结:CNN Image Retrieval Learns from BoW:Unsupervised Fine-Tuning with Hard Example:CNN Image Retrie
- OOP面向对象——封装
- HDU-5748 Bellovin 【LIS(STL应用)】
- 《VR入门系列教程》之5---应用方向
- Table 'performance_schema.session_variables' doesn't exist.
- 计算机网络--传输层
- LeetCode - Longest Palindromic Substring
- 最大公约数(gcd)辗转相除法
- tjut 4633
- L2-010. 排座位-PAT团体程序设计天梯赛GPLT(并查集)
- bzoj3531: [Sdoi2014]旅行