应该是这个吧
2024-05-20 17:47:43
发布于:上海
27阅读
0回复
0点赞
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int longestIncreasingSubsequence(vector<int>& seq) {
int n = seq.size();
vector<int> dp(n, 1);
for (int i = 1; i < n; i++) {
for (int j = 0; j < i; j++) {
if (seq[i] > seq[j]) {
dp[i] = max(dp[i], dp[j] + 1);
}
}
}
return *max_element(dp.begin(), dp.end());
}
int main() {
int n;
cin >> n;
vector<int> seq(n);
for (int i = 0; i < n; i++) {
cin >> seq[i];
}
cout << longestIncreasingSubsequence(seq) << endl;
return 0;
}
这里空空如也
有帮助,赞一个