Cod sursa(job #534621)

Utilizator SheepBOYFelix Liviu SheepBOY Data 15 februarie 2011 21:50:34
Problema Subsir 2 Scor 18
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
#include<stdio.h>
//#include<Windows.h>
#define MAX 5010

long long n,v[MAX],best[MAX],rec[MAX];

int FndMax(int pos)
{
	int a,max=-2000000;
	a=pos;
	rec[a]=-1;
	--pos;
	
	while(pos>-1)
	{
		if(max<v[pos] && v[pos]< v[a])
		{
			max=v[pos];
			rec[a]=pos;
		}
			--pos;
	}
	if(rec[a]>-1)
		return best[rec[a]];
	else
		return 0;
}
int main()
{
	int i,j;
	
//	SetPriorityClass(GetCurrentProcess(),256);
	
	freopen("subsir2.in","r",stdin);
	freopen("subsir2.out","w",stdout);
	
	scanf("%d",&n);
	for(i=0;i<n;++i)
		scanf("%d",v+i);
	
	int max=-1000002;
	for(i=0;i<n;++i)
	{
		best[i]=1+FndMax(i);
		if(max<best[i])
			max=best[i];
	}
	//reconstr sol
	
	printf("%d",max);
	return 0;
}