标签:des style blog http color os io for
题解:
不用O(nlogn)也能过吧,不过不想写了,直接照搬上一题的代码
代码:
1 var a,sta:array[0..5010] of longint; 2 i,top,n,j:longint; 3 function search(x:longint):longint; 4 var l,r,mid:longint; 5 begin 6 l:=1;r:=top; 7 while l<>r do 8 begin 9 mid:=(l+r) div 2; 10 if sta[mid]>x then r:=mid else l:=mid+1; 11 end; 12 exit(l); 13 end; 14 function lis:longint; 15 begin 16 top:=1;sta[1]:=a[1]; 17 for i:=2 to n do 18 begin 19 if a[i]<sta[1] then j:=1 20 else if a[i]>=sta[top] then j:=top+1 21 else j:=search(a[i]); 22 if j>top then begin inc(top);sta[top]:=a[i];end; 23 if a[i]<sta[j] then sta[j]:=a[i]; 24 end; 25 exit(top); 26 end; 27 begin 28 assign(input,‘input.txt‘);assign(output,‘output.txt‘); 29 reset(input);rewrite(output); 30 readln(n); 31 for i:=1 to n do read(a[i]); 32 writeln(lis); 33 close(input);close(output); 34 end.
BZOJ1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛,布布扣,bubuko.com
BZOJ1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛
标签:des style blog http color os io for
原文地址:http://www.cnblogs.com/zyfzyf/p/3907735.html