Pagini recente » Cod sursa (job #1456590) | Cod sursa (job #3029925) | Cod sursa (job #215069) | Atasamentele paginii qsasdasgegs | Cod sursa (job #1294419)
#include <iostream>
#include <fstream>
using namespace std;
#define nmax 10009
ifstream in("scmax.in");
ofstream out("scmax.out");
int lung[nmax], v[nmax], pred[nmax], i, j, lmax = 0;
void subsir (int n) {
lung[1] = 1;
for (i = 2; i <= n; i++) {
lmax = 0;
for (j = 1; j < i; j++)
if (v[j] < v[i])
if (lung[j] > lmax) {
lmax = lung[j];
pred[i] = j;
}
lung[i] = 1 + lmax;
}
}
void reconstruire (int p) {
if (pred[p] != 0)
reconstruire(pred[p]);
out << v[p] << " ";
}
int main() {
int n, maxim = 0, poz = 1;
in >> n;
for (i = 1; i <= n; i++) in >> v[i];
lung[1] = 1;
subsir(n);
for (i = 1; i <= n; i++){
if (lung[i] > maxim) {
maxim = lung[i];
poz = i;
}
}
out << lung[poz] << endl;
reconstruire(poz);
return 0;
}