参考
查看原帖
参考
23807
taoxinyue2016楼主2016/12/5 17:35
var a:array[1..100]of longint;
  k,n,i,t:longint;
  function up(o:longint):longint;
  var i,j:longint;
    f:array[0..100]of longint;
  begin
    fillchar(f,sizeof(f),0);
    f[0]:=0;
    f[1]:=1;
    for i:=2 to o-1 do
      for j:=i+1 to o do
        if(a[i]<a[j])and(f[i]+1>f[j])then f[j]:=f[i]+1;
    up:=0;
    for i:=0 to o do
      if up<f[i]then up:=f[i];
    up:=o-up;
  end;
  function down(o:longint):longint;
  var i,j:longint;
    f:array[0..100]of longint;
  begin
    fillchar(f,sizeof(f),0);
    f[o]:=1;
    for i:=o to n-1 do
      for j:=i+1 to n do
        if(a[i]>a[j])and(f[i]+1>f[j])then f[j]:=f[i]+1;
    down:=0;
    for i:=o to n do
      if down<f[i]then down:=f[i];
    down:=n-o-down;
  end;
begin
  readln(n);
  for i:=1 to n do
    read(a[i]);
  k:=99999;
  for i:=1 to n do
    begin
      t:=up(i)+down(i);
      if t<k then k:=t;
    end;
  if k=1 then writeln(0) else writeln(k);
  readln;readln;
end.
2016/12/5 17:35
加载中...