BZOJ1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛
2014-08-12 17:01
531 查看
1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛
Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 665 Solved: 419
[Submit][Status]
Description
Farmer John养了N(1 <= N <= 5,000)头奶牛,每头牛都有一个不超过32位二进制数的正整数编号。FJ希望奶牛们在进食前,能按编号从小到大的顺序排好队,但奶牛们从不听他的话。为了让奶牛们养成这个习惯,每次开饭时,FJ从奶牛中顺序地挑出一些,这些奶牛的编号必须按挑出的顺序递增。然后FJ让被挑出的奶牛们吃饭——其他奶牛就只能饿肚子了。 现在,你得到了这一次开饭前队伍中从前到后所有奶牛的编号。奶牛们想请你计算一下,按照FJ的规定,最多有多少头奶牛能吃上饭? 比如说,有11头奶牛按以下顺序排好了队(数字代表奶牛的编号) 2 5 18 3 4 7 10 9 11 8 15 对于这个队列,最多可以让7头奶牛吃上饭,她们的编号分别为2,3,4,7,10,11,15。队列2,5,3,10,15是不合法的,因为第3头奶牛的编号(3)小于她前面一头奶牛的编号(5)。Input
* 第1行: 一个整数,N * 第2..?行: 除了最后一行,每一行都包含恰好20个用空格隔开的整数,依次表 示队伍中从前到后的奶牛的编号。如果N不能整除20,那么最后一 行包含的数字不到20个Output
* 第1行: 输出按照FJ的规定,最多可以挑出的奶牛的数目Sample Input
112 5 18 3 4 7 10 9 11 8 15
Sample Output
7HINT
题解:不用O(nlogn)也能过吧,不过不想写了,直接照搬上一题的代码
代码:
var a,sta:array[0..5010] of longint; i,top,n,j:longint; function search(x:longint):longint; var l,r,mid:longint; begin l:=1;r:=top; while l<>r do begin mid:=(l+r) div 2; if sta[mid]>x then r:=mid else l:=mid+1; end; exit(l); end; function lis:longint; begin top:=1;sta[1]:=a[1]; for i:=2 to n do begin if a[i]<sta[1] then j:=1 else if a[i]>=sta[top] then j:=top+1 else j:=search(a[i]); if j>top then begin inc(top);sta[top]:=a[i];end; if a[i]<sta[j] then sta[j]:=a[i]; end; exit(top); end; begin assign(input,'input.txt');assign(output,'output.txt'); reset(input);rewrite(output); readln(n); for i:=1 to n do read(a[i]); writeln(lis); close(input);close(output); end.
View Code
相关文章推荐
- bzoj1669 [Usaco2006 Oct]Hungry Cows饥饿的奶牛
- 【动态规划】bzoj1669 [Usaco2006 Oct]Hungry Cows饥饿的奶牛
- bzoj1669 [Usaco2006 Oct]Hungry Cows饥饿的奶牛
- [BZOJ1669][Usaco2006 Oct]Hungry Cows饥饿的奶牛
- bzoj1669 [Usaco2006 Oct]Hungry Cows饥饿的奶牛
- bzoj1669 [Usaco2006 Oct]Hungry Cows饥饿的奶牛(nlogn求最长不下降子序列)
- bzoj 1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛 暴力
- BZOJ1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛
- bzoj1669 [Usaco2006 Oct]Hungry Cows饥饿的奶牛
- BZOJ 1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛|动态规划
- bzoj 1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛【dp+树状数组+hash】
- BZOJ 1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛( LIS )
- BZOJ1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛
- 【BZOJ】1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛(lis)
- 【BZOJ】1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛 最长上升子序列
- bzoj 1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛
- 1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛 (DP)
- 1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛
- BZOJ 1666: [Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏
- bzoj 1667: [Usaco2006 Oct]Cows on Skates滑旱冰的奶牛(BFS)