1.9 A circus is designing a tower routine consisting of people standing atop one another’s
shoulders. For practical and aesthetic reasons, each person must be both shorter and
lighter than the person below him or her. Given the heights and weights of each person
in the circus, write a method to compute the largest possible number of people in such
a tower.
EXAMPLE:
Input(ht, wt) : (65, 100) (70, 150) (56, 90) (75, 190) (60, 95) (68, 110)
Output: The longest tower is length 6 and includes from top to bottom:
shoulders. For practical and aesthetic reasons, each person must be both shorter and
lighter than the person below him or her. Given the heights and weights of each person
in the circus, write a method to compute the largest possible number of people in such
a tower.
EXAMPLE:
Input(ht, wt) : (65, 100) (70, 150) (56, 90) (75, 190) (60, 95) (68, 110)
Output: The longest tower is length 6 and includes from top to bottom:
(56,90) (60,95) (65,100) (68,110) (70,150) (75,190)
排序应该是不可避免的吧。
如果只是要求身高或者体重,直接排序就好。现在两者都要考虑,那么可以先按身高升序排列,(要求 shorter and lighter,是不是相同也不行?),然后求体重序列的 最长上升子序列(不严格的话,就是最长不下降序列)。
排序用快排就行,不过如果给的数据本来就有序的话,还是考虑插入什么的比较好。
最长上升序列的话
f[0]:=maxlongint;
t:=0;
for i:=2 to n do
if a[i]<f[t] then
begin
inc(t);
f[t]:=a[i];
end
else
for j:=1 to i do
if a[i]>=f[j] then begin f[j]:=a[i];break;end;
writeln(t);