Free pie
Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 18519 accepted submission (s): 6193
Problem description all said there would be no pie in the sky, but one day Gameboy was walking on the path home, And suddenly there were a lot of pies in the sky. It is really good to say that Gameboy's character is good. This Pie won't fall anywhere, and it will fall within 10 meters of his side. If the pie falls to the ground, it cannot be eaten, so Gameboy immediately unmounts his backpack to pick it up. But because neither side of the trail can stand, he can only pick up on the trail. Since Gameboy is always playing games in the room, although he is an agile player in the game, he is very slow in reality, A falling pie can only be reached within one meter of movement per second. Now mark the path with coordinates:
In order to simplify the problem, it is assumed that the pie falls to the 11 positions 0-10 in the next period of time. At the beginning, Gameboy stood at the position 5, so in the first second, he could only receive pies from one of the three positions, namely, 4, 5, and 6. How many pies can Gameboy receive at most? (Assuming his backpack can accommodate an infinite number of pies)
There are multiple groups of input data. The first behavior of each group of data is a positive integer N (0 <n <100000), indicating that there are n pies falling onto this path. In the final N rows, each row has two integers x, t (0 <t <100000), indicating that there is a pie on the second t at the X point. Multiple pies may be dropped at the same point in a second. When n = 0, the input ends.
Each group of input data corresponds to a row of output. Output an integer m, indicating that GameBoy can be connected to a maximum of M pies.
Tip: the input data volume in this question is relatively large. It is recommended to use scanf to read data. Using CIN may time out.
Sample Input
65 14 16 17 27 28 30
Sample output
4
Here we use top-down. I personally think it would be better to adopt the bottom-up method, that is, the reverse cycle by time can be less judged. Final output arr [0] [5]
# Include <stdio. h> # include <string. h> int N; int arr [100000] [13]; int opts [13], a, B, T; int mymax (int A, int B, int C) {A = A> B? A: B; return a> C? A: C;} int main () {While (scanf ("% d", & N), n) {memset (ARR, 0, sizeof (ARR )); for (INT I = 0; I <n; I ++) {scanf ("% d", & A, & B ); arr [B] [A + 1] ++; If (T <B) t = B;} memset (OPTs, 0, sizeof (OPTs )); for (INT I = 1; I <5; I ++) {// The first few rows of for (Int J = 0; j <6-i; j ++) Arr [I] [J] = 0; For (Int J = 12; j> 6 + I; j --) arr [I] [J] = 0 ;}for (INT I = 2; I <= T; I ++) for (Int J = 1; j <= 11; j ++) Arr [I] [J] + = mymax (ARR [I-1] [J-1], arr [I-1] [J], arr [I-1] [J + 1]); int max = 0; For (Int J = 1; j <= 11; j ++) if (max <arr [T] [J]) max = arr [T] [J]; printf ("% d \ n", max) ;}return 0 ;}