The number of pies in each position is only one second. It is related to the maximum number of pies in the left and right positions ..
He can also be seen as a data tower ..
Find the maximum value from the back ..
# Include <stdio. h>
# Include <string. h>
# Include <iostream>
# Include <cmath>
# Include <algorithm>
Using namespace STD;
Int s [11] [100001];
Int YY [11];
Int E, F;
Int maxn (INT y, int U, int K)
{
Int T;
If (Y> U)
T = y;
Else
T = u;
Return T> K? T: K;
}
Int maxnm (INT y, int U)
{
Return y> U? Y: U;
}
Int main ()
{
Int;
While (~ Scanf ("% d", & ))
{
If (A = 0)
Break;
Int maxnn = 0;
Memset (S, 0, sizeof (s ));
For (INT I = 0; I <A; I ++)
{
Scanf ("% d", & E, & F );
S [E] [f] ++;
If (maxnn <F) maxnn = F;
}
For (INT I = maxnn; I> 0; I --)
{
S [0] [I-1] + = maxnm (s [0] [I], s [1] [I]);
S [10] [I-1] + = maxnm (s [10] [I], s [9] [I]);
For (Int J = 1; j <= 9; j ++)
S [J] [I-1] + = maxn (s [J-1] [I], s [J] [I], s [J + 1] [I]);
}
Printf ("% d \ n", s [5] [0]);
}
Return 0;
}