| 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 | String<unsigned int, Block<> > pos;
Longest increasing subsequence
13 | longestIncreasingSubsequence(seq,pos);
Output the longest increasing subsequence
14 | for(int i = 0; i<(int) length(seq); ++i) {
15 | ::std::cout << seq[i] << ',';
16 | }
17 | ::std::cout << ::std::endl;
18 | ::std::cout << "Lis: " << ::std::endl;
19 | for(int i = length(pos)-1; i>=0; --i) {
20 | ::std::cout << seq[pos[i]] << ',';
21 | }
22 | ::std::cout << ::std::endl;
23 | return 0;
24 | }
See Graph, longestIncreasingSubsequence SeqAn - Sequence Analysis Library - www.seqan.de