Skip to content

Commit 8ee7e0f

Browse files
committed
adding LIS algorithm
1 parent 0567f25 commit 8ee7e0f

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

longestIncreasingSubsequence.cpp

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include<bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
int lis(int arr[], int n)
6+
{
7+
int lis[n];
8+
lis[0] = 1;
9+
for(int i=0; i<n; ++i)
10+
{
11+
lis[i] = 1;
12+
for(int j=0; j<i; ++j)
13+
if(arr[i] > arr[j] && lis[j] + 1 > lis[i])
14+
lis[i] = lis[j] + 1;
15+
}
16+
return lis[n-1];
17+
}
18+
19+
int main()
20+
{
21+
int arr[] = { 10, 22, 9, 33, 21, 50, 41, 60 };
22+
int n = sizeof(arr)/sizeof(arr[0]);
23+
printf("Length of lis is %d\n", lis( arr, n ) );
24+
return 0;
25+
}

0 commit comments

Comments
 (0)