56 std::cout << std::setw(14) << std::left << label <<
": [";
57 for (
size_t i = 0; i < arr.
size(); ++i)
75 template <
typename Fn>
76 void run_scenario(
const char * label,
79 const char * res_label,
80 const char * len_label)
82 std::cout << label <<
"\n";
85 const auto r = compute_fn(seq);
87 std::cout << std::setw(14) << std::left << len_label <<
": " <<
r.length <<
"\n";
103 std::cout <<
"\n=== Longest Increasing Subsequence Toolkit ===\n\n";
107 Array<int> seq = {10, 9, 2, 5, 3, 7, 101, 18};
108 run_scenario(
"Scenario A: Classic LIS", seq,
110 "One LIS",
"LIS length");
111 std::cout << std::setw(14) << std::left <<
"Length-only" <<
": "
120 run_scenario(
"Scenario B: Already sorted", seq,
122 "One LIS",
"LIS length");
130 run_scenario(
"Scenario C: Reverse sorted", seq,
132 "One LIS",
"LIS length");
140 run_scenario(
"Scenario D: Longest non-decreasing subsequence", seq,
142 "One LNDS",
"LNDS length");
149 std::cout <<
"Scenario E: Decreasing subsequence via comparator\n";
158 std::cout << std::setw(14) << std::left <<
"LDS length" <<
": "
159 << lds.length <<
"\n";
160 std::cout << std::setw(14) << std::left <<
"Non-inc len" <<
": "
161 << lnds_desc.length <<
"\n";
165 std::cout <<
"\nDone.\n";
Longest Increasing Subsequence (LIS) algorithms.
Simple dynamic array with automatic resizing and functional operations.
constexpr size_t size() const noexcept
Return the number of elements stored in the stack.
int main()
Demonstrates usage of Aleph-w LIS/LNDS utilities by running several example scenarios and printing th...
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.
LIS_Result< T > longest_increasing_subsequence(const Array< T > &seq, Compare cmp=Compare())
Compute the Longest Increasing Subsequence (strictly increasing).
void print_rule()
Prints a horizontal rule for example output separation.
size_t lis_length(const Array< T > &seq, Compare cmp=Compare())
Compute only the length of the LIS (no reconstruction).
void print_array(const char *label, const Container &a)