abccbazj 2010-08-10 19:08:00
点我顶贴
收藏
删除
只过2个点
var f:array[0..2000]of longint;
i,j,tail,n,k,min:longint;
a:array[0..3000]of longint;
function find(x:longint):longint;
var l,r,mid:longint;
begin
l:=1;r:=tail;
while l<=r do
begin
mid:=(l+r) shr 1;
if f[mid]=x then exit(mid) else
begin if f[mid]<x then l:=mid+1 else r:=mid-1;end;
end;
exit(l);
end;
begin
readln(n);
for i:=1 to n do
begin
read(a[i]);
a[i+n]:=a[i];
end;
min:=100000000;
for k:=1 to n do
begin
tail:=0;
fillchar(f,sizeof(f),0);
for i:=k to k+n-1 do
begin
j:=find(a[i]);
if j<=tail then f[j]:=a[i]
else begin inc(tail);f[tail]:=a[i];end;
end;
if tail<min then min:=tail;
end;
writeln(min);
end.