Cod sursa(job #534614)

Utilizator SheepBOYFelix Liviu SheepBOY Data 15 februarie 2011 21:42:41
Problema Subsir 2 Scor 2
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.64 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;
	while(pos)
	{
		if(max<v[pos] && v[pos]< v[a])
			rec[a]=pos;
		--pos;
	}
	return rec[a];
}
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+best[FndMax(i)];
		if(max<best[i])
			max=best[i];
	}
	//reconstr sol
	
	printf("%d",max);
	return 0;
}