Files
Data-Structure/Algorithm/DP-DynamicProgramming/Linear-DP/B3637 最长上升子序列.cpp
2025-09-15 22:16:09 +08:00

29 lines
615 B
C++

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct cmp{
bool operator()(const pair<int, int>& a, const pair<int, int>& b){
if(a.first != b.first) return a.first > b.first;
return a.second < b.second;
}
};
int main(){
int n;
cin >> n;
vector<int> a(n);
for(int i = 0; i < n; i++){
cin >> a[i];
}
//dp[i]->数列前i个的最长上升子列 pair(长度, 最大值)
vector<int> dp(n, 1);
for(int i = 0; i < n; i++){
for(int j = 0; j < i; j++){
if(a[i] > a[j]) dp[i] = max(dp[i], dp[j] + 1);
}
}
int m = *max_element(dp.begin(), dp.end());
cout << m << endl;
return 0;
}