f(x,t)=max{ f(x-1,t-1) , f(x,t-1) , f(x+1,t-1) };
left=(5-t)>0?(5-t):0;
right=(5+t)<10?(5+t):10;
for left to right <-- i
res=max{f(maxt,i)};
#include <stdio.h> #include <string.h> #define mmax(x,y,z) (x)>((y)>(z)?(y):(z))?(x):((y)>(z)?(y):(z)) int gird[100000+10][11]; int main(){ int i,j; int n,x,t; int left,right; int maxt; int res; int x1,x2,x3; while(~scanf("%d",&n)&&n){ memset(gird,0,sizeof(gird)); maxt=0; while(n--){ scanf("%d%d",&x,&t); maxt=maxt>t?maxt:t; gird[t][x]++; } for(i=1;i<=maxt;++i){ for(j=0;j<=10;++j){ if(j==0){ gird[i][j]+=mmax(-1,gird[i-1][j],gird[i-1][j+1]); }else if(j==10){ gird[i][j]+=mmax(gird[i-1][j-1],gird[i-1][j],-1); }else{ gird[i][j]+=mmax(gird[i-1][j-1],gird[i-1][j],gird[i-1][j+1]); } } } res=-1; // left=(5-t)>0?(5-t):0; // right=(5+t)<10?(5+t):10; if(5-t<0) left=0; else left=5-t; if(5+t>10) right=10; else right=5+t; for(i=left;i<=right;++i){ if(gird[maxt][i]>res) res=gird[maxt][i]; } printf("%d ",res); } return 0; }