Skip to content

Commit

Permalink
Create longest_increasing_subsequence.cpp (srbcheema1#147)
Browse files Browse the repository at this point in the history
To find the longest increasing subsequence in an array of integers.
  • Loading branch information
pBuddhi authored and srbcheema1 committed Oct 9, 2018
1 parent 02fcac4 commit 0bec0f2
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Dynamic Programing/longest_increasing_subsequence.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <iostream>
using namespace std;
int longestIncreasingSubsequence(int A[],int size){
int dp[size];
for(int i=0;i<size;i++) dp[i] = 1;
for(int i=1;i<size;i++){
for(int j=0;j<i;j++){
if(A[j]<A[i]){
dp[i] = max(dp[i],dp[j]+1);
}
}
}
int lis = 0;
for(int i=0;i<size;i++) {
lis = max(lis,dp[i]);
}

return lis;
}
int main() {

int A[] = {1,3,5,9,8};
cout<<longestIncreasingSubsequence(A,5);
return 0;
}

0 comments on commit 0bec0f2

Please sign in to comment.