Pagini recente » Cod sursa (job #1121076) | Cod sursa (job #1610271) | Cod sursa (job #1856419) | Cod sursa (job #1123970) | Cod sursa (job #533645)
Cod sursa(job #533645)
type vector=array[0..100000] of longint;
var v,l,p:vector;
n,max,im:longint;
procedure citire;
var i:longint;
begin
assign(input,'scmax.in');reset(input);
readln(n);
for i:=1 to n do
read(v[i]);
close(input);
end;
procedure dinamic;
var i,j:longint;
begin
l[n]:=1;
p[n]:=-1;
for i:=n-1 downto 1 do begin
l[i]:=1;
p[i]:=-1;
for j:=i+1 to n do
if (v[i]<v[j]) and (1+l[j]>l[i]) then begin
l[i]:=l[j]+1;
p[i]:=j;
if l[i]>max then begin
max:=l[i];
im:=i;
end;
end;
end;
end;
procedure scrie;
var i:longint;
begin
assign(output,'scmax.out');rewrite(output);
writeln(max);
i:=im;
repeat
write(v[i],' ');
i:=p[i];
until i=-1;
close(output);
end;
begin
citire;
dinamic;
scrie;
end.