Longest Increasing Subsequence

| Example Program Longest Increasing Subsequence Longest increasing subsequence code example File "graph_algo_lis.cpp" A tutorial about the longest increasing subsequence algorithm.
1 | #include <iostream>
2 | #include <seqan/graph_algorithms.h>
3 |
4 | using namespace seqan;
5 |
6 | int main() {
Creation of a simple sequence of numbers
7 | String<unsigned int> seq;
8 | appendValue(seq, 5); appendValue(seq, 3); appendValue(seq, 4);
9 | appendValue(seq, 9); appendValue(seq, 6); appendValue(seq, 2);
10 | appendValue(seq, 1); appendValue(seq, 8); appendValue(seq, 7);
11 | appendValue(seq, 10);
Out-parameter: A string of positions belonging to the longest increasing subsequence
12 | typedef Position<String<unsigned int> >::Type TPosition;
13 | String<TPosition, Block<> > pos;
Longest increasing subsequence
14 | longestIncreasingSubsequence(seq,pos);
Output the longest increasing subsequence
15 | for(int i = 0; i<(int) length(seq); ++i) {
16 | ::std::cout << seq[i] << ',';
17 | }
18 | ::std::cout << ::std::endl;
19 | ::std::cout << "Lis: " << ::std::endl;
20 | for(int i = length(pos)-1; i>=0; --i) {
21 | ::std::cout << seq[pos[i]] << ',';
22 | }
23 | ::std::cout << ::std::endl;
24 | return 0;
25 | }
See longestIncreasingSubsequence, Graph SeqAn - Sequence Analysis Library - www.seqan.de

Page built @2011/02/08 21:37:01