Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,48 +0,0 @@
|
|||
function Get-LongestSubsequence ( [int[]]$A )
|
||||
{
|
||||
If ( $A.Count -lt 2 ) { return $A }
|
||||
|
||||
# Start with an "empty" pile
|
||||
# (We will only store the top value in each "pile".)
|
||||
$Pile = @( [int]::MaxValue )
|
||||
$Last = 0
|
||||
|
||||
# Hashtable to hold the back pointers
|
||||
$BP = @{}
|
||||
|
||||
# For each number in the orginal sequence...
|
||||
ForEach ( $N in $A )
|
||||
{
|
||||
# Find the first pile with a value greater than N
|
||||
$i = 0..$Last | Where { $N -lt $Pile[$_] } | Select -First 1
|
||||
|
||||
# Place N on the pile
|
||||
$Pile[$i] = $N
|
||||
|
||||
# Set the back pointer for this value to the value of the previous pile
|
||||
$BP["$N"] = $Pile[$i-1]
|
||||
|
||||
# If this is the previously empty pile, add a new empty pile
|
||||
If ( $i -eq $Last )
|
||||
{
|
||||
$Pile += @( [int]::MaxValue )
|
||||
$Last++
|
||||
}
|
||||
}
|
||||
|
||||
# Ignore the empty pile
|
||||
$Last--
|
||||
|
||||
# Start with the value of the last pile
|
||||
$N = $Pile[$Last]
|
||||
$S = @( $N )
|
||||
|
||||
# Add the remainder of the values by walking through the back pointers
|
||||
ForEach ( $i in $Last..1 )
|
||||
{
|
||||
$S += ( $N = $BP["$N"] )
|
||||
}
|
||||
|
||||
# Return the series (reversed into the correct order)
|
||||
return $S[$Last..0]
|
||||
}
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
( Get-LongestSubsequence 3, 2, 6, 4, 5, 1 ) -join ', '
|
||||
( Get-LongestSubsequence 0, 8, 4, 12, 2, 10, 6, 16, 14, 1, 9, 5, 13, 3, 11, 7, 15 ) -join ', '
|
||||
Loading…
Add table
Add a link
Reference in a new issue