codevs1044

来源:互联网 发布:路由器js注入 编辑:程序博客网 时间:2024/05/07 19:06

题目地址:http://codevs.cn/problem/1044/

分析:

贪心+动归

代码:

Var  h,sum:array [1..20] of longint;  n:longint;Procedure input;  begin    n:=0;    while not eoln do      begin        inc(n);        read(h[n]);        sum[n]:=1;      end;  end;Procedure more;  var    i,j:longint;    max:longint;  begin    for i:=n-1 downto 1 do      begin        max:=0;        for j:=i+1 to n do if(h[j]<=h[i]) and (sum[j]>max) then max:=sum[j];        sum[i]:=max+1;      end;    max:=0;    for i:=1 to n do if sum[i]>max then max:=sum[i];    writeln(max);  end;Procedure less;  var    hh:array [1..20] of longint;    i,j,k,p:longint;  begin    hh[1]:=h[1];k:=1;    for i:=2 to n do      begin        p:=0;        for j:=1 to k do          if hh[j]>h[i] then            if p=0 then p:=j                   else if hh[j]<hh[p] then p:=j;        if p=0 then          begin            inc(k);            hh[k]:=h[i];          end               else          hh[p]:=h[i];      end;    writeln(k);  end;Begin  input;  more;  less;End.

0 0
原创粉丝点击