Finds the longest ascending subsequence of a permutation.
Use the following HTML code to embed the calculators within other websites:
Ascending Subsequence
std::vector<int>ascending_subsequence(
int
n
int*
a
)
This function searches for the longest ascending subsequence of a permutation using a dynamic programming
algorithm. It then returns a C++ vector storing the elements of the subsequence in the exact order they appeared
in the original array.
Example:
#include <codecogs/maths/combinatorics/permutations/ascending_subsequence.h>#include <iostream>int main(){int sigma[6] = {1, 5, 2, 4, 6, 3};
std::vector<int> result = Maths::Combinatorics::Permutations::ascending_subsequence(6, sigma);
std::cout << "The longest ascending subsequence of Sigma is:";
std::cout << std::endl;
for(int i = 0; i < result.size(); i++)
std::cout << result[i] << " ";
std::cout << std::endl;
return0;
}
Output:
The longest ascending subsequence of Sigma is:
1246