Longest increasing subsequence: Difference between revisions
Content added Content deleted
(Simpler D entry) |
No edit summary |
||
Line 180: | Line 180: | ||
<pre>a L.I.S. of [3, 2, 6, 4, 5, 1] is [2, 4, 5] |
<pre>a L.I.S. of [3, 2, 6, 4, 5, 1] is [2, 4, 5] |
||
a L.I.S. of [0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15] is [0, 2, 6, 9, 11, 15]</pre> |
a L.I.S. of [0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15] is [0, 2, 6, 9, 11, 15]</pre> |
||
=={{header|Swym}}== |
|||
Based on the Python video solution. |
|||
<lang swym> |
|||
Array.'lis' |
|||
{ |
|||
'stems' = Number.Array.mutableArray[ [] ] |
|||
forEach(this) 'value'-> |
|||
{ |
|||
'bestStem' = stems.where{==[] || .last < value}.max{.length} |
|||
stems.push( bestStem + [value] ) |
|||
} |
|||
return stems.max{.length} |
|||
} |
|||
[3,2,6,4,5,1].lis.trace |
|||
[0,8,4,12,2,10,6,14,1,9,5,13,3,11,7,15].lis.trace |
|||
</lang> |
|||
{{out}} |
|||
<pre> |
|||
3 4 5 |
|||
0 4 6 9 13 15 |
|||
</pre> |
|||
=={{header|Tcl}}== |
=={{header|Tcl}}== |