Skip to content

Instantly share code, notes, and snippets.

@rohit-nsit08
Created August 31, 2011 15:13
Show Gist options
  • Select an option

  • Save rohit-nsit08/1183804 to your computer and use it in GitHub Desktop.

Select an option

Save rohit-nsit08/1183804 to your computer and use it in GitHub Desktop.
longest increasing sub sequence using dynamic programming
// 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