Cod sursa(job #1090334)

Utilizator fhandreiAndrei Hareza fhandrei Data 22 ianuarie 2014 16:53:51
Problema Subsir crescator maximal Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 0.84 kb
// Include
#include <fstream>
#include <algorithm>
using namespace std;

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

// Functii
void route(int node);

// Variabile
ifstream in("scmax.in");
ofstream out("scmax.out");

int num;
int values[sz], best[sz], father[sz];

// Main
int main()
{
	in >> num;
	for(int i=1 ; i<=num ; ++i)
		in >> values[i];
	
	for(int i=1 ; i<=num ; ++i)
	{
		best[i] = 1;
		for(int j=1 ; j<i ; ++j)
		{
			if(values[j] < values[i])
			{
				if(best[i] < best[j] + 1)
				{
					best[i] = best[j] + 1;
					father[i] = j;
				}
			}
		}
	}
	
	int pos = max_element(best+1, best+num+1) - best;
	
	out << best[pos] << '\n';
	route(pos);
	out << '\n';
	
	in.close();
	out.close();
	return 0;
}

void route(int node)
{
	if(father[node])
		route(father[node]);
	out << values[node] << ' ';
}