-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path8.LIS(print).cpp
More file actions
44 lines (37 loc) · 759 Bytes
/
8.LIS(print).cpp
File metadata and controls
44 lines (37 loc) · 759 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
38
39
40
41
42
43
44
#include<bits/stdc++.h>
using namespace std;
int main(){
//freopen("input.txt","r",stdin);
int n;
cin>>n;
int arr[n];
for(int i=0; i<n; i++){
cin>>arr[i];
}
int lcs[n];
for(int i=0; i<n; i++){
lcs[i] = 1;
}
for(int i=1; i<n; i++){
for(int j=0; j<n; j++){
if(arr[j]<arr[i] && lcs[j]+1>lcs[i]){
lcs[i] = lcs[j]+1;
}
}
}
int length = lcs[0];
for(int i=0; i<n; i++){
if(length<lcs[i]) length=lcs[i];
}
int max = length;
//cout<<length<<endl;
vector<int> v;
for(int i=n-1; i>=0; i--){
if(max==lcs[i]){ v.push_back(i);
max--;
}
}
for(int i=0; i<v.size(); i++){
cout<<arr[v[i]]<<endl;
}
}