Cod sursa(job #729219)

Utilizator fhandreiAndrei Hareza fhandrei Data 29 martie 2012 13:15:43
Problema Subsir crescator maximal Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.89 kb
//Include
#include <fstream>
using namespace std;

//Constante
const int MAX_SIZE = (int)1e5+1;

//Functii
void drum(int x);

//Variabile
ifstream in("scmax.in"); // Si tu ai nume naspa
ofstream out("scmax.out");

int n;
int maxFound, maxFoundPoz;
int best[MAX_SIZE], tata[MAX_SIZE], oldVector[MAX_SIZE];

//Main
int main()
{
	in >> n >> oldVector[1];
	best[1] = 1;
	for(int i=2 ; i<=n ; ++i)
	{
		in >> oldVector[i];
		maxFound = maxFoundPoz = 0;
		
		for(int j=1 ; j<i ; ++j)
			if(oldVector[j] < oldVector[i])
			{
				if(best[j] > maxFound)
				{
					maxFoundPoz = j;
					maxFound = best[j];
				}
			}
		best[i] = max(best[i-1], maxFound + 1);
		tata[i] = maxFoundPoz;
	}
	out << best[n] << '\n';
	
	drum(n);
	out << '\n';
	
	in.close();
	out.close();
	return 0;
}

void drum(int x)
{
	if(tata[x])
		drum(tata[x]);
	out << oldVector[x] << ' ';
}