类似于最长不下降子序列
type node=record up,data,down:longint; end; var i,j,t,n,max:longint; a:array[1..105]of node; begin readln(n); for i:=1 to n do read(a[i].data); for i:=1 to n do begin for j:=1 to i-1 do if a[j].data<a[i].data then begin if a[j].up>=a[i].up then a[i].up:=a[j].up+1; end end; for i:=n downto 1 do begin for j:=n downto i+1 do if a[i].data>a[j].data then begin if a[j].down>=a[i].down then a[i].down:=a[j].down+1; end; end; for i:=1 to n do if (a[i].up+a[i].down)>max then max:=a[i].up+a[i].down; writeln(n-max-1); end.
就是扫描两次。。
时间: 2024-10-23 06:01:40