-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathlis.cpp
More file actions
37 lines (30 loc) · 702 Bytes
/
Copy pathlis.cpp
File metadata and controls
37 lines (30 loc) · 702 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <iostream>
using namespace std;
int _lis(int arr[], int n, int *max_ref)
{
if (n == 1)
return 1;
int res, max_ending_here = 1;
for (int i = 1; i < n; i++)
{
res = _lis(arr, i, max_ref);
if (arr[i - 1] < arr[n - 1] && res + 1 > max_ending_here)
max_ending_here = res + 1;
}
if (*max_ref < max_ending_here)
*max_ref = max_ending_here;
return max_ending_here;
}
int lis(int arr[], int n)
{
int max = 1;
_lis(arr, n, &max);
return max;
}
int main()
{
int arr[] = {10, 22, 9, 33, 21, 50, 41, 60};
int n = sizeof(arr) / sizeof(arr[0]);
cout << "Length of lis is " << lis(arr, n);
return 0;
}