Skip to content

Commit 1da87fc

Browse files
Create increasing_subsequence.cpp
1 parent ed21cb4 commit 1da87fc

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

increasing_subsequence.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
int main() {
5+
int n;
6+
cin >> n;
7+
vector<int> dp;
8+
for (int i = 0; i < n; i++) {
9+
int x;
10+
cin >> x;
11+
auto it = lower_bound(dp.begin(), dp.end(), x);
12+
13+
if (it == dp.end()) { // Append it to the LIS
14+
dp.push_back(x);
15+
} else {
16+
*it = x; // It doesn't change the length of the LIS
17+
}
18+
}
19+
// DP vector isn't the LIS
20+
cout << dp.size() << endl;

0 commit comments

Comments
 (0)