From 5ab8a5088b729a9953b8dff1b2a985dc8fb2098b Mon Sep 17 00:00:00 2001 From: mzuenni Date: Mon, 27 Jun 2022 17:19:28 +0200 Subject: updated tcr --- math/longestIncreasingSubsequence.cpp | 44 +++++++++++++++++------------------ 1 file changed, 22 insertions(+), 22 deletions(-) (limited to 'math/longestIncreasingSubsequence.cpp') diff --git a/math/longestIncreasingSubsequence.cpp b/math/longestIncreasingSubsequence.cpp index 388e394..357ebcd 100644 --- a/math/longestIncreasingSubsequence.cpp +++ b/math/longestIncreasingSubsequence.cpp @@ -1,23 +1,23 @@ -vector longestIncreasingSubsequence(vector &seq) { - int n = seq.size(), lisLength = 0, lisEnd = 0; - vector L(n), L_id(n), parents(n); - for (int i = 0; i < n; i++) { - int pos = - lower_bound(L.begin(), L.begin() + lisLength, seq[i]) - L.begin(); - L[pos] = seq[i]; - L_id[pos] = i; - parents[i] = pos ? L_id[pos - 1] : -1; - if (pos + 1 > lisLength) { - lisLength = pos + 1; - lisEnd = i; - }} - // Ab hier Rekonstruktion der Sequenz. - vector result(lisLength); - int pos = lisLength - 1, x = lisEnd; - while (parents[x] >= 0) { - result[pos--] = x; - x = parents[x]; - } - result[0] = x; - return result; // Liste mit Indizes einer LIS. +vector lis(vector &seq) { + int n = seq.size(), lisLength = 0, lisEnd = 0; + vector L(n), L_id(n), parents(n); + for (int i = 0; i < n; i++) { + int pos = upper_bound(L.begin(), L.begin() + lisLength, + seq[i]) - L.begin(); + L[pos] = seq[i]; + L_id[pos] = i; + parents[i] = pos ? L_id[pos - 1] : -1; + if (pos + 1 > lisLength) { + lisLength = pos + 1; + lisEnd = i; + }} + // Ab hier Rekonstruktion der Sequenz. + vector result(lisLength); + int pos = lisLength - 1, x = lisEnd; + while (parents[x] >= 0) { + result[pos--] = x; + x = parents[x]; + } + result[0] = x; + return result; // Liste mit Indizes einer LIS. } -- cgit v1.2.3