Cod sursa(job #636162)

Utilizator andreivFMI - vacaroiu andrei andreiv Data 19 noiembrie 2011 17:30:58
Problema PalM Scor 100
Compilator cpp Status done
Runda .com 2011 Marime 0.61 kb
#include <cstdio>
#include <cstring>
int sol[505];
int main()
{
	int n,i,j,a=1,b,max=1,x,rez=0; 
	char s[505];
	
	freopen("palm.in","r",stdin);
	freopen("palm.out","w",stdout);
	scanf("%s",s);
	n=strlen(s);
	for (i=0;i<n;++i)
	{
		max=0;
		for (j=n-1;j>i;--j)
		{
			if (s[j]==s[i])
				a=max+2;
			if ((s[j]<=s[i]) && (sol[j]>max)) max=sol[j]; 
			if ((s[j]==s[i]) && (a>sol[j]))
				sol[j]=a;
			if ((s[j]==s[i]) && (sol[j]>sol[i])) sol[i]=sol[j];
		}
		if (max+1>sol[i]) sol[i]=max+1;
		if (rez<sol[i]) rez=sol[i];
	}
		
			
	printf("%d\n",rez);
return 0;
}