Cod sursa(job #486457)

Utilizator AndreiRSStatescu Andrei Rares AndreiRS Data 21 septembrie 2010 18:18:50
Problema Subsir crescator maximal Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 0.6 kb
#include <stdio.h>
#define DIM 100001

int N, X[DIM], L[DIM], T[DIM], pf;

void scm () {
	int i, j;
	scanf ("%d%d", &N, &X[1]);
	L[1] = pf = 1;
	
	for (i=2; i<=N; ++i) {
		scanf ("%d", &X[i]);
		for (j=1; j<i; ++j)
			if (X[j] < X[i] && L[j] >= L[i])
				L[i] = L[j]+1, T[i] = j;
		if (!L[i]) L[i]=1;
		if (L[pf] < L[i])
			pf = i;
	}
}

void afs (int p) {
	if ( !p ) {
		printf ("%d\n", L[pf]); 
		return;
	}
	afs (T[p]);
	printf ("%d ", X[p]);
}

int main () {
	freopen ("scmax.in", "r", stdin);
	freopen ("scmax.out", "w", stdout);
	
	scm ();
	afs (pf);
	
	return 0;
}