-
Notifications
You must be signed in to change notification settings - Fork 92
Expand file tree
/
Copy pathLIS.cpp
More file actions
35 lines (34 loc) · 683 Bytes
/
Copy pathLIS.cpp
File metadata and controls
35 lines (34 loc) · 683 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
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int LIS()
{
int n;
cin>>n; // Number of elements
vector<int> d; // A possible solution that is one of the Longest Increasing Subsequences
int elem;
for(int i=0;i<n;i++)
{
cin>>elem;
d.push_back(elem);
}
int dp[n];
for(int i=0;i<n;i++){
dp[i]=1;
}
for(int i=2;i<n;i++){
for(int j=i-1;j>=0;j--){
if(d[i]>=d[j]){
dp[i]=max(dp[i],dp[j]+1);
}
}
}
int ans=INT_MIN;
for(int i=0;i<n;i++){
if(ans<dp[i]){
ans=dp[i];
}
}
cout<<ans<<endl;
}