Created
August 31, 2011 15:13
-
-
Save rohit-nsit08/1183804 to your computer and use it in GitHub Desktop.
longest increasing sub sequence using dynamic programming
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
| // using dynamic programming | |
| #include <stdio.h> | |
| #define MAX 8 | |
| int get_length(int a[]) | |
| { | |
| int i,j; | |
| int length = 0; | |
| int dp[10]={1}; | |
| for(i=1;i<MAX;i++) | |
| { | |
| dp[i]=1; | |
| for(j=0;j<i;j++) | |
| { | |
| if(((dp[j]+1)>dp[j])&&(a[i]>a[j])) | |
| dp[i] = dp[j]+1; | |
| } | |
| if(dp[i]>length) | |
| length = dp[i]; | |
| } | |
| return length; | |
| } | |
| int main(int argc, char const *argv[]) | |
| { | |
| int sequence[MAX] = {1,5,2,4,3,5,4,6}; | |
| printf("length of longest increasing subsequece is %d\n",get_length(sequence)); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment