您的位置:首页 > 其它

求最长不下降序列

2017-02-27 20:59 253 查看
求最长不下降序列
Time Limit:1000MS  Memory Limit:65536K

Total Submit:398 Accepted:171
Description

设有n(n<=1000)个不相同的整数(小于32767)组成的数列,记为:

    a1,a2,...,an,其中任意两个数不相同。

  例如:3,18,7,14,10,12,23,41,16,24。

  若有 且有 。则称为长度为e的不下降序列。如上例中,3,18,23,24为一个长度为4的不下降序列,同时也有3,7,10,12,16,24长度为6的不下降序列。程序要求,当原始数列给出后,求出最长的不下降数列的长度。

Input

Output


Sample Input


10
3 18 7 14 10 12 23 41 16 24


Sample Output


6


Source

elba

公式:

  f[i]:=f[j]+1;

注意输出!!!

比较最大值!!!

var

  i,j,k,n,m,l,max:longint;

  a,f:array[1..1001]of longint;

begin

  readln(n);

  for i:=1 to n do

    begin

      read(a[i]);

    end;

  f
:=1;

  for i:=n-1 downto 1 do

    begin

      l:=1;

      for j:=i+1 to n do

        if (a[i]<a[j]) and (f[j]+1>l)

          then l:=f[j]+1;

      f[i]:=l;

    end;

  for i:=1 to n do

    if f[i]>max then max:=f[i];

  writeln(max);

end.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: