Question link: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1176
Free pie
Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 14396 accepted submission (s): 4763
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
Authorlwg
// AC 62 Ms 10432 K (by C ++) # include <stdio. h> # include <string. h> int pie [100005] [13]; int DP [100005] [13]; int maxn (int A, int B, int c) {A = A> B? A: B; A = A> C? A: C; return a;} int main () {int N, maxtime = 0, ANS = 0; int x, t; int I, J; while (scanf ("% d", & N )! = EOF & N) {memset (pie, 0, sizeof (PIE); memset (DP, 0, sizeof (DP); While (n --) {scanf ("% d", & X, & T); pie [T] [x + 1] ++; // pay attention to boundary processing due to J-1, so: Move all the pies to the next place. Otherwise, maxtime = maxtime> T? Maxtime: T ;}for (I = maxtime, j = 0; j <= 12; j ++) DP [I] [J] = pie [I] [J]; for (I = maxtime-1; I> = 1; I --) // Note: similar to the tower problem, recursive from bottom up for (j = 1; j <= 11; j ++) // due to the J-1, pay attention to the boundary processing, otherwise Wa is very miserable, strange is that after the first shift, write here (j = 0; j <= 11; j ++) too. amount, it turns out that I was wrong. After the shift, pie also fell on 1---11 DP [I] [J] = pie [I] [J] + maxn (DP [I + 1] [J-1], DP [I + 1] [J], DP [I + 1] [J + 1]); ans = maxn (DP [1] [5], DP [1] [6], DP [1] [7]); printf ("% d \ n", ANS) ;}return 0 ;}