Created
May 8, 2015 07:12
-
-
Save rickyzhang-cn/dc6685511839c0b413e7 to your computer and use it in GitHub Desktop.
Longest Increasing Subsequence
This file contains 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
#include <iostream> | |
using namespace std; | |
int lis(int A[], int n){ | |
int *d = new int[n]; | |
int len = 1; | |
for(int i=0; i<n; ++i){ | |
d[i] = 1; | |
for(int j=0; j<i; ++j) | |
if(A[j]<=A[i] && d[j]+1>d[i]) | |
d[i] = d[j] + 1; | |
if(d[i]>len) len = d[i]; | |
} | |
delete[] d; | |
return len; | |
} | |
int main(){ | |
int A[] = { | |
5, 3, 4, 8, 6, 7 | |
}; | |
cout<<lis(A, 6)<<endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment