拉拉拉拉拉拉~~~~~~~dp水水~~~~~~~~~~~~
好不容易AC之后,看status,发现这题被zzuli的小盆友们集体虐过,ORZ。。。
这题开始想得有问题,没考虑中间间隔时间大的话肿么样。今晚想了想,改成按时间DP,因为当前时间的状态只和上一秒状态有关。
所以直接用上一秒相邻两个以及自己(忘了这个,WA了几次)状态更新即可。当然,开始的时候需要存下馅饼的时间,地点,如果5可以到达的话,那么更新的时候加上去即可。
虽然很水,但是还是蛮开心的~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#include <queue>
#include <stack>
#include <math.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <limits.h>
#include <string.h>
#include <string>
#include <algorithm>
#define MID(x,y) ( ( x + y ) >> 1 )
#define L(x) ( x << 1 )
#define R(x) ( x << 1 | 1 )
#define BUG puts("here!!!")
using namespace std;
const int MAX = 100010;
const int MAX_N = 15;
int dp[MAX_N][MAX];
int tt[MAX_N][MAX];
int main()
{
int n,x,t;
while( ~scanf("%d",&n) && n )
{
memset(dp, 0, sizeof(dp));
memset(tt, 0, sizeof(tt));
int max_t = 0;
for(int i=0; i<n; i++)
{
scanf("%d%d",&x,&t);
max_t = max(max_t, t);
tt[x][t]++;
}
int ans = 0;
for(int i=1; i<=max_t; i++)
for(int k=0; k<=10; k++)
{
int t = dp[k][i-1];
if( k >= 1 ) t = max(t, dp[k-1][i-1]);
if( k <= 9 ) t = max(t, dp[k+1][i-1]);
dp[k][i] = t;
if( tt[k][i] && i >= abs(k-5) )
dp[k][i] += tt[k][i];
ans = max(ans, dp[k][i]);
}
printf("%d\n",ans);
}
return 0;
}