Đê tính số cách em dùng Dequeue.
procedure pro(i:longint);
begin
while (top>0) and (a[d[top]]<a[i]) do dec(top);
inc(top);
d[top]:=i;
if (top>0) and (res1<d[top-1]) then res1:=d[top-1];
end;
procedure nhap;
var f:text;
i:longint;
begin
assign(f,fi); reset(f);
readln(f,n,h);
for i:=1 to n do
begin
read(f,a[i]);
pro(i);
end;
res1:=n-res1+1;
close(f);
end;
Tính số ngày em tính theo số Catalan.
j:=2;
res:=1; n:=n+1;
for i:=n+2 to 2*n do
begin
res:=res*i;
while (j<=n) and (res mod j=0) do
begin
res:=res div j;
j:=j+1;
end;
if j>n then res:=res mod base;
end;
CODE: http://ideone.com/RQxSSN