Pagini recente » Cod sursa (job #1054199) | Cod sursa (job #1330947) | Cod sursa (job #2406146) | Cod sursa (job #2523798) | Cod sursa (job #1438752)
#include <fstream>
#include <vector>
using namespace std;
ifstream fin("scmax.in");
ofstream fout("scmax.out");
const int MAX = 100001;
int dp[MAX], father[MAX], n, v[MAX], maxx, maxxi;
vector <int> s;
int main() {
fin >> n;
for (int i = 1; i <= n; i++) {
fin >> v[i];
dp[i] = 1;
}
for (int i = 1; i <= n; i++)
for (int j = i - 1; j >= 1; j--)
if(v[j] < v[i] && dp[j] + 1 > dp[i]) {
dp[i] = dp[j] + 1;
father[i] = j;
if (dp[i] > maxx) {
maxx = dp[i];
maxxi = i;
}
}
fout << maxx << '\n';
s.push_back(maxxi);
while (father[maxxi]) {
s.push_back(father[maxxi]);
maxxi = father[maxxi];
}
while (s.size()) {
fout << v[s.back()] << ' ';
s.pop_back();
}
return 0;
}