Hdu1176:
Free pie
Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 15875 accepted submission (s): 5270
Problem description It is said that the sky will not drop pies, but one day Gameboy is walking on the path home, suddenly there are 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)
Input 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.
Output 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
(X, t) (coordinate, time)
65 14 16 17 27 28 30
Sample output
4
Code:
# Include <iostream> using namespace STD; int DP [1001] [12]; int main () {int N, I, j, maxtime; int x, t; while (scanf ("% d", & N), n! = 0) {maxtime = 0; memset (DP, 0, sizeof (DP); for (I = 0; I <n; I ++) {scanf ("% d", & X, & T); // drops the pie at point X at the T level. DP [T] [x] ++; if (maxtime <t) {maxtime = T ;}} for (I = maxtime-1; I> = 0; I --) {DP [I] [0] + = max (DP [I + 1] [1], DP [I + 1] [0]); // time = I, X = 0: Max; For (j = 1; j <11; j ++) {DP [I] [J] + = max (DP [I + 1] [J-1], DP [I + 1] [J + 1]), DP [I + 1] [J]);} printf ("% d \ n", DP [0] [5]);}