HDU 5748 Bellovin(LIS)

    xiaoxiao2024-07-26  11

    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

    #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; }
    转载请注明原文地址: https://ju.6miu.com/read-1291067.html
    最新回复(0)