Cod sursa(job #741946)

Utilizator alexdmotocMotoc Alexandru alexdmotoc Data 27 aprilie 2012 16:31:39
Problema Subsir crescator maximal Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.84 kb
#include <cstdio>
#include <iostream>

using namespace std;

#define maxN 100005

int best[maxN] , sol[maxN] , x[maxN] , tata[maxN];
int best_max , poz , poz_max , dim , N;

int main ()
{
	freopen ("scmax.in" , "r" , stdin);
	freopen ("scmax.out" , "w" , stdout);
	
	scanf ("%d" , &N);
	
	for (int i = 1 ; i <= N ; ++i)
	{
		scanf ("%d" , &x[i]);
		
		best_max = -1;
		
		for (int j = 1 ; j < i ; ++j)
			if (best[j] > best_max && x[j] < x[i])
			{
				best_max = best[j];
				poz = j;
			}
		
		if (best_max == -1)
		{
			best[i] = 1;
			continue;
		}
		
		
		best[i] = best_max + 1;
		tata[i] = poz;
		
		poz_max = i;
	}
	
	printf ("%d\n" , best[N]);
	
	
	for (int i = poz_max ; i >= 1 ; i = tata[i])
		sol[++dim] = x[i];
	
	for (int i = dim ; i >= 1 ; --i)
		printf ("%d " , sol[i]);
	
	return 0;
}