Skip to content

Instantly share code, notes, and snippets.

@cbdavide
Last active July 27, 2017 23:54
Show Gist options
  • Save cbdavide/81ce40fac1ab90fb31a5c37b6fef0e4a to your computer and use it in GitHub Desktop.
Save cbdavide/81ce40fac1ab90fb31a5c37b6fef0e4a to your computer and use it in GitHub Desktop.
Longest Increasing Subsequence
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