I have forgotten
my Password

Or login with:

  • Facebookhttp://facebook.com/
  • Googlehttps://www.google.com/accounts/o8/id
  • Yahoohttps://me.yahoo.com
get GPL
COST (GBP)
this unit 2.09
sub units 0.19
+
0

Ascending Subsequence

Finds the longest ascending subsequence of a permutation.
Controller: CodeCogs

Dependents

Info

Interface

C++

Ascending Subsequence

 
std::vector<int>ascending_subsequenceintn
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;
  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

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.