in reply to Longest Increasing Subset
You may find the following code helpful:
use strict; use warnings; my @list = qw(20 60 65 50 55 70 10 30 40 90 51 52); my @runs; for my $item (@list) { my @newRuns = [$item]; for my $run (@runs) { next if $item <= $run->[-1]; push @newRuns, [@$run]; push @$run, $item; } push @runs, @newRuns; } @runs = sort {@$a <=> @$b} @runs; @runs = grep {@{$runs[-1]} == @$_} @runs; print "@$_\n" for @runs;
Prints:
20 60 65 70 90 20 50 55 70 90 20 30 40 51 52 10 30 40 51 52
|
|---|