Cod sursa(job #542750)

Utilizator andrei.dAndrei Diaconeasa andrei.d Data 26 februarie 2011 22:10:49
Problema Subsir crescator maximal Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 0.71 kb
#include <cstdio>

#define file_in "scmax.in"
#define file_out "scmax.out"

int i,j,n,lmax,v[101000],best[101000],poz[101000],p;

void scrie(){
	
	int i;
	i=p;
	while(i!=-1){
		printf("%d ", v[i]);
		i=poz[i];
	}
}
	

int main(){
	
	freopen(file_in,"r",stdin);
	freopen(file_out,"w",stdout);
	
	scanf("%d", &n);
	for (i=1;i<=n;++i)
		 scanf("%d", &v[i]);
	
	best[n]=1;
	poz[n]=-1;
	for (i=n-1;i>=1;--i){
		best[i]=1;
		poz[i]=-1;
		for (j=i+1;j<=n;++j)
			 if (v[i]<v[j] && best[i]<best[j]+1){
				 best[i]=best[j]+1;
				 poz[i]=j;
				 //p=i;
			 }
	}
	
    lmax=0;
	for (i=1;i<=n;++i) if (best[i]>lmax) lmax=best[i],p=i;
	
	printf("%d\n", lmax);
	scrie();
	
	return 0;
	
}