Cod sursa(job #329999)

Utilizator popoiu.georgeGeorge Popoiu popoiu.george Data 8 iulie 2009 13:41:16
Problema Subsir crescator maximal Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 0.59 kb
#include<stdio.h>
using namespace std;

long long v[100001];
int n,best[100001],poz[100001];

int main()
{
freopen("scmax.in","r",stdin);
freopen("scmax.out","w",stdout);
int i,j,max,p;
scanf("%d",&n);
for(i=1;i<=n;i++)scanf("%lld",&v[i]);
best[n]=1;
poz[n]=-1;
max=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;
			if(best[i]>max) {max=best[i];p=i;}
			}
		}	
	}
printf("%d\n",max);
i=p;
while(i!=-1)
	{
	printf("%lld ",v[i]);
	i=poz[i];
	}
return 0;
}