-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
56 lines (45 loc) · 1.08 KB
/
main.cpp
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
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>
#include <vector>
using namespace std;
int LLIS(vector<int> sequence, int n);
int main() {
vector<int> arr;
arr.push_back(1);
arr.push_back(7);
arr.push_back(4);
arr.push_back(5);
arr.push_back(5);
/*
arr.push_back(2);
arr.push_back(5);
arr.push_back(1);
arr.push_back(9);
arr.push_back(7);
arr.push_back(5);
arr.push_back(6);
arr.push_back(8);
*/
cout << LLIS(arr, arr.size()) << endl;
return 0;
}
int LLIS(vector<int> sequence, int n) {
vector<vector<int> > L(n);
L[0].push_back(sequence.at(0));
int maxLen = 1, maxIndex = 0;
for (int i = 1; i < n; i++) {
for (int j = 0; j < i; j++) {
if (sequence.at(j) < sequence.at(i) and L.at(i).size() < L.at(j).size()) {
L[i] = L[j];
}
}
L[i].push_back(sequence[i]);
if (maxLen < L[i].size())
maxLen = L[i].size();
maxIndex = i;
}
vector<int> max = L[maxIndex];
for (int x : max)
cout << x << " ";
cout << endl;
return maxLen;
}