study-cpp/ssoier/1281/1281.cpp

41 lines
874 B
C++

// ID:1281 TITLE:最大上升子序列
#include <iostream>
#include <vector>
int main() {
int length;
std::cin >> length;
std::vector<int> v(length);
std::vector<std::vector<int>> result;
for (int i = 0; i < length; i++) {
int input_element;
std::cin >> input_element;
v[i] = input_element;
}
{
bool flag = true;
int prev = 0;
while (!v.empty()) {
if (*v.rbegin() > prev) {
prev = *v.rbegin();
v.pop_back();
result.end()->push_back(prev);
} else {
flag = false;
result.push_back(std::vector<int>());
}
}
}
int max = 0, max_index = 0;
for (int i = 0; i < result.size(); i++) {
if (result[i].size() > max) {
max_index = i;
max = result[i].size();
}
}
for (auto v : result[max_index]) {
std::cout << v << " ";
}
std::cout << std::endl;
}