Cod sursa(job #783292)

Utilizator GodiesVlad Voicu Godies Data 2 septembrie 2012 15:15:22
Problema Subsir crescator maximal Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1.3 kb
/* 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 print(int n) {
	FILE *fp = fopen("scmax.out", "w");
	for (int i = 0; i < n; i++) {
		fprintf(fp, "%d", v[i]);
	}
}

void compute(int n) {
	int globalmax = 1;
	int i, j;
	int max = 0;
	int p = -1;
	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;
				}
			}
		}
	}
	printf("%d " , max);
	printf("\n");
	std::vector<int> aux;
	while (p > 0) {
		aux.push_back(v[p]);
		p = pre[p];
	}
	for (i = aux.size() - 1; i >= 0; i--) {
		printf("%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;
}