求最长不下降序列
2017-02-28 17:09
204 查看
求最长不下降序列
Time Limit:1000MS Memory Limit:65536K
Total Submit:402 Accepted:174
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
Sample Output
逆推方法如下:
var
map:array[1..1000] of longint;
dis:array[1..1000] of longint;
i,n,j,max:longint;
begin
readln(n);
for i:=1 to n do
read(map[i]);
dis
:=1;
for i:=n-1 downto 1 do
begin
max:=1;
for j:=i+1 to n do
begin
if (map[i]<map[j]) and (dis[j]+1>max) then
max:=dis[j]+1;
dis[i]:=max;
end;
end;
max:=0;
for i:=1 to n do
if dis[i]>max then max:=dis[i];
write(max);
end.
Time Limit:1000MS Memory Limit:65536K
Total Submit:402 Accepted:174
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
逆推方法如下:
var
map:array[1..1000] of longint;
dis:array[1..1000] of longint;
i,n,j,max:longint;
begin
readln(n);
for i:=1 to n do
read(map[i]);
dis
:=1;
for i:=n-1 downto 1 do
begin
max:=1;
for j:=i+1 to n do
begin
if (map[i]<map[j]) and (dis[j]+1>max) then
max:=dis[j]+1;
dis[i]:=max;
end;
end;
max:=0;
for i:=1 to n do
if dis[i]>max then max:=dis[i];
write(max);
end.
相关文章推荐
- 动态规划实现最大连续子序列和,最长不下降子序列和最长公共子序列
- POJ - 1952 BUY LOW, BUY LOWER(最长下降子序列,计数)
- 最长不下降子序列的O(n*logn)算法
- 拦截导弹(规律:下降子序列的个数等于最长上升子序列的长度)
- 最长不下降子序列的O(n*logn)算法
- 【最长下降子序列】北大 POJ 1065 Wooden Sticks
- hdu1160 FatMouse's Speed 最长下降子序列 及其打印
- 计蒜客 最长不下降子序列 (nlogn算法)
- 最长不下降序列(HNOI’97)
- 最长不下降子序列(LIS)
- 求最长不下降序列
- 20180321最长不下降序列
- 最长不下降序列
- hdu1160 FatMouse's Speed (求最长严格下降子序列路径)
- HDU Problem E [ 最长下降子序列 堆箱子]——基础dp模板题变式
- hdoj1160 FatMouse's Speed ( STL + 最长下降子序列 /DP)
- 最长不下降子序列 动态规划
- POJ 1952 BUY LOW, BUY LOWER DP 最长下降序列求个数
- 最长下降序列——中高级
- 最长上升子序列 和 最长不下降子序列