-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathLcs.cpp
More file actions
31 lines (31 loc) · 678 Bytes
/
Lcs.cpp
File metadata and controls
31 lines (31 loc) · 678 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
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int lcs(int array[],int n)
{
vector<int> temp;
temp.push_back(array[0]);
for(int i=1;i<n;i++)
{
if(array[i]>temp.back())
temp.push_back(array[i]);
else
{
int x = lower_bound(temp.begin(),temp.end(),array[i])-temp.begin();
temp[x] = array[i];
}
}
return temp.size();
}
int main()
{
int n;
cout << "Array Size:";
cin >> n;
int array[n];
cout << "Enter array elements : ";
for(int i=0;i<n;i++)
cin >> array[i];
cout << "Length of longest increasing subsequence : " << lcs(array,n);
return 0;
}