主题:TJU1004怎么会超时
经典的防御导弹,我编的超时了,谁帮帮我啊
var
s,a,prt,s1:array[1..20]of integer;
i,j,k,l,n,max,n1,sum:integer;
flag:boolean;
begin
n:=0;flag:=true;sum:=0;
while not eoln do
begin
read(s[n+1]);
a[n+1]:=1;
prt[n+1]:=0;
inc(n);
end;
while true do
begin
for i:=2 to n do
begin
max:=0;
for j:=1 to i-1 do
if (s[j]>=s[i])and(a[j]>max) then begin max:=a[j]; k:=j; end;
a[i]:=max+1;
prt[i]:=k;
end;
max:=0;inc(sum);
for i:=1 to n do if a[i]>max then begin max:=a[i]; l:=i; end;
if flag then write(max,' ');
while prt[l]<>0 do
begin
s[l]:=-1;
l:=prt[l];
end;
s[l]:=-1;
flag:=false;n1:=0;
for i:=1 to n do
if s[i]<>-1 then begin s1[n1+1]:=s[i]; inc(n1); end;
if n1=0 then break;
s:=s1;n:=n1;
end;
writeln(sum);
end.
var
s,a,prt,s1:array[1..20]of integer;
i,j,k,l,n,max,n1,sum:integer;
flag:boolean;
begin
n:=0;flag:=true;sum:=0;
while not eoln do
begin
read(s[n+1]);
a[n+1]:=1;
prt[n+1]:=0;
inc(n);
end;
while true do
begin
for i:=2 to n do
begin
max:=0;
for j:=1 to i-1 do
if (s[j]>=s[i])and(a[j]>max) then begin max:=a[j]; k:=j; end;
a[i]:=max+1;
prt[i]:=k;
end;
max:=0;inc(sum);
for i:=1 to n do if a[i]>max then begin max:=a[i]; l:=i; end;
if flag then write(max,' ');
while prt[l]<>0 do
begin
s[l]:=-1;
l:=prt[l];
end;
s[l]:=-1;
flag:=false;n1:=0;
for i:=1 to n do
if s[i]<>-1 then begin s1[n1+1]:=s[i]; inc(n1); end;
if n1=0 then break;
s:=s1;n:=n1;
end;
writeln(sum);
end.