1 /*****************************************************2 title: Xiao Ming Series Problem--Xiao Ming sequence (hdu 4521)3 Links:http://acm.hdu.edu.cn/showproblem.php?pid=45214 algorithm: The longest ascending subsequence sequence of Lis5 6 ******************************************************/7#include <cstdio>8#include <cstring>9#include <algorithm>Ten#include <iostream> One#include <queue> A using namespacestd; - - Const intmx=100005; the intD[MX],DP[MX],A[MX]; -queue<int>Q; - - intBinserch (intLintRintcut) + { - while(l<=R) + { A intM= (l+r) >>1; at if(cut>d[m]&&cut<=d[m+1])returnm; - if(Cut>d[m]) l=m+1; - Elser=m-1; - } - return 0; - } in - intLIS (intNintk) to { + intlen=1, J; -Fill (d,d+n+3, MX); thed[1]=a[0]; * for(inti=k+1; i<n;i++) $ {Panax Notoginseng if(A[i]>d[len]) j=len+1; - ElseJ=binserch (1, Len,a[i]) +1; thedp[i]=J; + Q.push (i); A the intcut=Q.front (); + - Q.pop (); $d[dp[cut]]=min (A[cut],d[dp[cut]]); $len=Max (Len,dp[cut]); - } - while(!q.empty ()) the { - intcut=Q.front ();Wuyi Q.pop (); thelen=Max (Len,dp[cut]); - } Wu returnLen; - } About $ intMain () - { - intn,d; - while(~SCANF ("%d%d",&n,&d)) A { + while(!q.empty ()) Q.pop (); the for(intI=0; i<n;i++) scanf ("%d",&a[i]); - for(intI=1; i<=d;i++) $ { thedp[i]=1; the Q.push (i); the } theprintf"%d\n", LIS (n,d)); - } in}
Hdu 5421 Xiao Ming series Problem--Xiao Ming sequence (lis longest ascending subsequence)