Mercurial > lbo > hg > juliaplay
changeset 17:f6833e5295d6
DP: Liss with reconstruction
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Tue, 28 Feb 2023 13:43:46 +0100 |
parents | a4a917da5365 |
children | f099b399e2f0 |
files | julia/dp.jl |
diffstat | 1 files changed, 17 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/julia/dp.jl Tue Feb 28 13:37:49 2023 +0100 +++ b/julia/dp.jl Tue Feb 28 13:43:46 2023 +0100 @@ -96,6 +96,23 @@ c end +function recursive_liss(v::AbstractVector{<:Integer}) + N = length(v) + prev, L = zeros(Int, N), zeros(Int, N) + Lmax = recursive_liss(v, 1, 1, 0, prev, L) + + # Reconstruct: + i = L[Lmax] + l = Lmax + liss = zeros(Int, Lmax) + while i > 0 + liss[l] = v[i] + i = prev[i] + l -= 1 + end + liss +end + function recursive_liss(v::AbstractVector{<:Integer}, last=1, i=1, l=0, prev=zeros(Int, length(v)), L=zeros(Int, length(v)), Lmax=[0])::Int if i > length(v) return l