68 template <
typename T,
class Compare>
72 size_t lo = 0, hi =
tails.size();
75 const size_t mid = lo + (hi - lo) / 2;
84 template <
typename T,
class Compare>
88 size_t lo = 0, hi =
tails.size();
91 const size_t mid = lo + (hi - lo) / 2;
113 template <
typename T,
class Compare = Aleph::less<T>>
116 Compare
cmp = Compare())
118 const size_t n = seq.
size();
132 for (
size_t i = 0; i < n; ++i)
136 if (lo ==
tails.size())
138 tails.append(seq[i]);
147 parent(i) = lo > 0 ?
tail_idx[lo - 1]
148 : std::numeric_limits<size_t>::max();
157 result(
k - 1) = seq[idx];
176 template <
typename T,
class Compare = Aleph::less<T>>
180 const size_t n = seq.
size();
187 for (
size_t i = 0; i < n; ++i)
191 if (lo ==
tails.size())
192 tails.append(seq[i]);
214 template <
typename T,
class Compare = Aleph::less<T>>
217 Compare
cmp = Compare())
219 const size_t n = seq.
size();
230 for (
size_t i = 0; i < n; ++i)
234 if (pos ==
tails.size())
236 tails.append(seq[i]);
245 parent(i) = pos > 0 ?
tail_idx[pos - 1]
246 : std::numeric_limits<size_t>::max();
249 const size_t len =
tails.size();
252 for (
size_t k = len;
k > 0; --
k)
254 result(
k - 1) = seq[idx];
Standard functor implementations and comparison objects.
Simple dynamic array with automatic resizing and functional operations.
static Array create(size_t n)
Create an array with n logical elements.
constexpr size_t size() const noexcept
Return the number of elements stored in the stack.
void reserve(size_t cap)
Reserves cap cells into the array.
int cmp(const __gmp_expr< T, U > &expr1, const __gmp_expr< V, W > &expr2)
size_t lower_bound_pos(const Array< T > &tails, const T &value, Compare cmp)
size_t upper_bound_pos(const Array< T > &tails, const T &value, Compare cmp)
Main namespace for Aleph-w library functions.
LIS_Result< T > longest_nondecreasing_subsequence(const Array< T > &seq, Compare cmp=Compare())
Compute the Longest Non-Decreasing Subsequence.
Divide_Conquer_DP_Result< Cost > divide_and_conquer_partition_dp(const size_t groups, const size_t n, Transition_Cost_Fn transition_cost, const Cost inf=dp_optimization_detail::default_inf< Cost >())
Optimize partition DP using divide-and-conquer optimization.
std::decay_t< typename HeadC::Item_Type > T
LIS_Result< T > longest_increasing_subsequence(const Array< T > &seq, Compare cmp=Compare())
Compute the Longest Increasing Subsequence (patience sorting).
size_t lis_length(const Array< T > &seq, Compare cmp=Compare())
Compute only the length of the LIS (no reconstruction).
Result of a LIS computation.
Array< T > subsequence
One optimal LIS.
size_t length
Length of the LIS.
Dynamic array container with automatic resizing.