# include <iostream>
# include <iomanip>
namespace
{
{
std::cout << std::setw(14) << std::left << label << ": [";
for (
size_t i = 0; i < arr.
size(); ++i)
{
if (i > 0)
std::cout << ", ";
std::cout << arr[i];
}
std::cout << "]\n";
}
template <typename Fn>
void run_scenario(const char * label,
Fn compute_fn,
const char * res_label,
const char * len_label)
{
std::cout << label << "\n";
print_rule();
const auto r = compute_fn(seq);
std::cout << std::setw(14) << std::left << len_label <<
": " <<
r.length <<
"\n";
}
}
{
std::cout << "\n=== Longest Increasing Subsequence Toolkit ===\n\n";
{
run_scenario("Scenario A: Classic LIS", seq,
"One LIS", "LIS length");
std::cout << std::setw(14) << std::left << "Length-only" << ": "
std::cout << "\n";
}
{
run_scenario("Scenario B: Already sorted", seq,
"One LIS", "LIS length");
std::cout << "\n";
}
{
run_scenario("Scenario C: Reverse sorted", seq,
"One LIS", "LIS length");
std::cout << "\n";
}
{
run_scenario("Scenario D: Longest non-decreasing subsequence", seq,
"One LNDS", "LNDS length");
std::cout << "\n";
}
{
std::cout << "Scenario E: Decreasing subsequence via comparator\n";
std::cout << std::setw(14) << std::left << "LDS length" << ": "
<< lds.length << "\n";
std::cout << std::setw(14) << std::left << "Non-inc len" << ": "
<< lnds_desc.length << "\n";
}
std::cout << "\nDone.\n";
return 0;
}
Longest Increasing Subsequence (LIS) via patience sorting.
Simple dynamic array with automatic resizing and functional operations.
constexpr size_t size() const noexcept
Return the number of elements stored in the stack.
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 (patience sorting).
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)