Last active
July 27, 2017 23:54
-
-
Save cbdavide/81ce40fac1ab90fb31a5c37b6fef0e4a to your computer and use it in GitHub Desktop.
Longest Increasing Subsequence
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef vector<int> vi; | |
/** | |
* LONGEST INCREASING SUBSEQUENCE | |
* COMPLEXITY O(N^2) | |
*/ | |
int lci(vi &A) { | |
vi DP (A.size(), 1); | |
for(int i=1; i<(int)A.size(); i++) { | |
for(int j=0; j<i; j++) { | |
if(A[j] < A[i]) | |
DP[i] = max(DP[i], DP[j] + 1); | |
} | |
} | |
int maxi = 0; | |
for(int i=0; i<DP.size(); i++) | |
maxi = max(maxi, DP[i]); | |
return maxi; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment