HDU 5748 Bellovin(LIS)
2016-08-12 19:15
190 查看
Bellovin
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1045 Accepted Submission(s): 468
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
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1045 Accepted Submission(s): 468
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
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; #define M 100010 #define INF 0x3f3f3f3f int a[M], dp[M], n, f[M]; void init() { for(int i=1; i<=n; i++) { dp[i] = INF; f[i] = 0; } } int main() { int t; scanf("%d", &t); while(t--) { scanf("%d", &n); for(int i=1; i<=n; i++) { scanf("%d", &a[i]); } init(); for(int i=1; i<=n; i++) { int j = lower_bound(dp+1, dp+n+1, a[i]) - dp; dp[j] = a[i]; f[i] = j; } for(int i=1; i<=n; i++) { printf("%d", f[i]); if(i == n) printf("\n"); else printf(" "); } } return 0; }
相关文章推荐
- HDU 5748 Bellovin (LIS)
- HDU 5748 Bellovin(LIS)
- HDU-5748-Bellovin【LIS】
- HDU 5748 Bellovin(LIS nlogn)
- Bellovin【hdu 5748 dp lis】
- HDU 5748 (Bellovin LIS)
- HDU - 5748 Bellovin【nlgn+LIS】
- hdu_5748_Bellovin(LIS)
- hdu-5748 Bellovin(LIS)
- hdu 5748 Bellovin(LIS)
- HDU-5748 Bellovin 【LIS(STL应用)】
- 【HDU】-5748-Bellovin(LIS,变化)
- 【HDU】5748 - Bellovin(LIS)
- HDU 5748 Bellovin
- HDU Problem 5748 Bellovin 【LIS】
- HDU - 5748 Bellovin —— 最长上升子序列
- HDU 5748 Bellovin(dp+二分)
- HDU 5748 Bellovin
- HDU 5748 BestCoder Round #84 Bellovin (LIS)(树状数组)
- Bellovin HDU 5748