Pagini recente » Cod sursa (job #209474) | Cod sursa (job #1711962) | Borderou de evaluare (job #1100979) | Cod sursa (job #1493164) | Cod sursa (job #783296)
Cod sursa(job #783296)
/* Vlad Voicu 2012 */
/* This program is free software. It comes without any warranty, to
* the extent permitted by applicable law. You can redistribute it
* and/or modify it under the terms of the Do What The Fuck You Want
* To Public License, Version 2, as published by Sam Hocevar. See
* http://sam.zoy.org/wtfpl/COPYING for more details. */
#include <cstdio>
#include <string>
#include <vector>
#include <iostream>
unsigned int v[100001];
unsigned int best[100001];
unsigned int pre[100001];
void compute(int n) {
int i, j;
int max = 0;
int p = -1;
FILE *fp = fopen("scmax.out", "w");
for (i = 0; i < n; i++) {
best[i] = 1;
pre[i] = -1;
for (j = 0; j < i; j++) {
if ((v[j] < v[i]) && best[i] < best[j] + 1) {
best[i] = best[j] + 1;
pre[i] = j;
if (best[i] > max) {
max = best[i];
p = i;
}
}
}
}
fprintf(fp, "%d ", max);
fprintf(fp, "\n");
std::vector<int> aux;
while (p > 0) {
aux.push_back(v[p]);
p = pre[p];
}
for (i = aux.size() - 1; i >= 0; i--) {
fprintf(fp, "%d ", aux[i]);
}
}
int main() {
int n;
FILE *fp = fopen("scmax.in", "r");
fscanf(fp, "%d", &n);
for (int i = 0; i < n; ++i) {
fscanf(fp, "%d", &v[i]);
}
compute(n);
fclose(fp);
return 0;
}