User:GeorgeBills/Strictly increasing sequence
Appearance
The original page is at longest increasing subsequence problem.
Longest common sequence version
[edit]Simple version
[edit]The following is code for finding the longest strictly increasing sequence [1]:
int lsis( int* a, int N ) { int *best, *prev, i, j, max = 0; best = (int*) malloc ( sizeof( int ) * N ); prev = (int*) malloc ( sizeof( int ) * N ); for ( i = 0; i < N; i++ ) best[i] = 1, prev[i] = i; for ( i = 1; i < N; i++ ) for ( j = 0; j < i; j++ ) if ( a[i] > a[j] && best[i] < best[j] + 1 ) best[i] = best[j] + 1, prev[i] = j; for ( i = 0; i < N; i++ ) if ( max < best[i] ) max = best[i]; free( best ); free( prev ); return max; }
Optimized version
[edit]See also
[edit]External links
[edit]- The problem as applied to genetics
- The Algorithm Design Manual: Longest Increasing Sequence
- The Algorithmist wiki page on the problem