传送门
首先我们可以倒着做一次最长下降序列,记录以x结尾的最长下降序列的长度。
然后反过来,我们就有了以x开头的最长上升序列的长度。
我们正着推过去,可以知到当长度大于x是这个点可选,此时长度-1,输出答案。
有点说不清楚,没看懂的请转弯
var
a,f:array [0..10005] of longint;
n,i,j,max,m,l,last:longint;
begin
read(n);
for i:=1 to n do read(a[i]);
for i:=1 to n do f[i]:=1;
for i:=n-1 downto 1 do
for j:=i+1 to n do
if (a[i]<a[j]) and (f[i]<f[j]+1) then f[i]:=f[j]+1;
max:=0;
for i:=1 to n do if (f[i]>max) then max:=f[i];
read(m);
for i:=1 to m do begin
read(l);
if (l>max) then begin writeln('Impossible'); continue; end;
last:=0;
for j:=1 to n do
if (f[j]>=l) and (a[j]>last) then begin
write(a[j]); if (l<>1) then write(' ');
last:=a[j]; dec(l);
if (l=0) then break;
end;
writeln;
end;
end.