FUNCTION
Ascending_Subsequence
Finds the longest ascending subsequence of a permutation.
Interface
#include <codecogs/maths/combinatorics/permutations/ascending_subsequence.h>
using namespace Maths::Combinatorics::Permutations;
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;
return 0;
}
Output:
The longest ascending subsequence of Sigma is:
1 2 4 6
References
SUBSET, a C++ library of combinatorial routines, http://www.csit.fsu.edu/~burkardt/cpp_src/subset/subset.html
Returns
a C++ vector storing the actual elements of the ascending subsequence
This function's source code is only visible to registered users — documentation and the calculator above are free to use either way. Sign in to see it.