Pagini recente » Cod sursa (job #2954507) | Cod sursa (job #2556830) | Cod sursa (job #57186) | Cod sursa (job #486101) | Cod sursa (job #1677257)
#include <iostream>
#include <vector>
#include <fstream>
#define N_MAX 100000
std::fstream fin ("scmax.in", std::ios::in);
std::fstream fout ("scmax.out", std::ios::out);
int n;
std::vector <long long> v;
int d[N_MAX];
void dinamic () {
int max = 0;
d[0] = 1;
for (int i = 1; i < n; i++) {
max = 0;
for (int j = 0; j < i; j++) {
if (v[i] > v[j] && max < d[j]) {
max = d[j];
}
}
d[i] = max + 1;
}
fout << d[n-1] << '\n';
}
void solutie (int, int);
void get_sol () {
int max = 0;
int pmax = -1;
for (int i = 0; i < n; i++) {
if (d[i] > max) {
max = d[i];
pmax = i;
}
}
solutie (pmax, max);
}
void solutie (int pmax, int max) {
if (pmax >= 0) {
if (d[pmax] == max) {
solutie (pmax - 1, max - 1);
fout << v[pmax] << " ";
} else
solutie (pmax - 1, max);
}
}
int main (void) {
fin >> n;
long temp_l;
for (int i = 0; i < n; i++) {
fin >> temp_l;
v.push_back (temp_l);
}
dinamic ();
get_sol ();
fin.close();
fout.close();
return 0;
}