记录一个菜逼的成长。。
简单的记忆化搜索。
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
#define ALL(v) (v).begin(),(v).end()
#define cl(a,b) memset(a,b,sizeof(a))
const int INF = 0x7fffffff;
const int maxn = 100000 + 10;
int dp[maxn][12],a[maxn][12],mx;
int dfs(int T,int x)
{
if(x < 0 || x > 10)return 0;
if(dp[T][x] != -1)return dp[T][x];
if(T > mx)return 0;
int ret = 0;
for( int i = -1; i <= 1; i++ )
ret = max(ret,dfs(T+1,x+i));
return dp[T][x] = ret + a[T][x];
}
int main()
{
int n;
while(~scanf("%d",&n),n){
cl(a,0);cl(dp,-1);
mx = 0;
for( int i = 0; i < n; i++ ){
int x,T;scanf("%d%d",&x,&T);
a[T][x] ++;
mx = max(mx,T);
}
printf("%d\n",dfs(0,5));
}
return 0;
}