Ascending Subsequence
Finds the longest ascending subsequence of a permutation.
Controller: CodeCogs
Dependents
Interface
C++
Ascending Subsequence
std::vector<int>ascending_subsequence( | int | n | |
int* | a | ) |
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.htmlReturns
- a C++ vector storing the actual elements of the ascending subsequence
Authors
- Lucian Bentea (August 2005)
Source Code
Source code is available when you agree to a GP Licence or buy a Commercial Licence.
Not a member, then Register with CodeCogs. Already a Member, then Login.