杭电1176
1 #include<stdio.h> 2 #include<string.h> 3 int a[100005][11]; 4 int main() 5 { 6 int n,i,j,t,time; 7 while(~scanf("%d",&n)&&n) 8 { 9 time=0; 10 memset(a,0,sizeof a); 11 while(n--) 12 { 13 scanf("%d%d",&i,&j); 14 if(j>time) 15 time=j; 16 a[j][i]++; 17 } 18 for(i=time-1; i>0; --i) 19 for(j=0; j<11; ++j) 20 { 21 if(j==0) 22 a[i][j] += a[i+1][j]>a[i+1][j+1]?a[i+1][j]:a[i+1][j+1]; 23 else if(j==10) 24 a[i][j] += a[i+1][j]>a[i+1][j-1]?a[i+1][j]:a[i+1][j-1]; 25 else 26 { 27 t = a[i+1][j] > a[i+1][j+1] ? a[i+1][j] : a[i+1][j+1]; 28 a[i][j] += a[i+1][j-1] > t ? a[i+1][j-1] : t; 29 } 30 } 31 t=a[1][4]>a[1][5]?a[1][4]:a[1][5]; 32 t=a[1][6]>t?a[1][6]:t; 33 printf("%d\n",t); 34 } 35 }