数塔类型
#include<iostream>
using namespace std;
int f[100000][11],b;
int max ( int x, int y)
{
if( x > y)
return x;
return y;
}
int Nmax(int a,int x,int c)
{
if (x>a) a=x;
if (c>a) a=c;
return a;
}
int main()
{
int x,n,t;
while (scanf("%d",&n) && n!=0)
{
b = 100001;
while (b>=0)
{
for (t=0;t<11;t++)
f[b][t]=0;
b--;
}
while (n>0)
{
scanf("%d%d",&x,&t);
f[t-1][x]++;
if (t-1>b)
b=t-1;
n--;
}
for (x=b;x>0;x--)
{
f[x-1][0]+=max(f[x][0],f[x][1]);
for (n=1;n<10;n++)
f[x-1][n]+=Nmax(f[x][n-1],f[x][n],f[x][n+1]);
f[x-1][10]+=max(f[x][9],f[x][10]);
}
printf("%d\n", Nmax(f[0][4],f[0][5],f[0][6]));
}
return 0;
}
/*
6
5 1
4 1
6 1
7 2
7 2
8 3
0 */