Cod sursa(job #443576)

Utilizator sebe14Moraru Sebastian sebe14 Data 17 aprilie 2010 17:03:58
Problema Subsir crescator maximal Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 0.5 kb
#include<fstream>
using namespace std;
ifstream f("scmax.in");
ofstream g("scmax.out");
int v[100001], l[100001], w[100001];
int main()
{
	int n,i,j,lmax,Lmax=0,poz;
	f>>n;
	for(i=1; i<=n; i++)
		f>>v[i];
	l[n]=1;
	for(i=n-1; i; i--){
		lmax=1;
		for(j=i+1; j<=n; j++)
			if(v[i]<v[j])
				if(lmax<l[j]+1){
					lmax=l[j]+1;
					w[i]=j;
				}
		l[i]=lmax;
		if(Lmax<l[i])
		{
			Lmax=l[i];
			poz=i;
		}
	}
	g<<Lmax<<"\n";
	while(poz){
		g<<v[poz]<<" ";
		poz=w[poz];
	}
	return 0;
}