Free pies
Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 27587 Accepted Submission (s): 9370
problem DescriptionSaid the sky will not drop pies, but one day Gameboy is walking home on the path, suddenly fell into the sky a lot of pie. Gameboy's character was so good that the pie was not lost elsewhere, and fell within 10 metres of his side. If the pie fell on the ground, of course, it could not eat, so Gameboy immediately remove the backpack to pick up. But because the trails could not stand on either side, he could only pick it up on the path. As Gameboy usually stay in the room to play games, although in the game is a skill Agile master, but in the reality of the motor is particularly dull, every second species only in the move not more than a meter in the range to catch falling pies. Now mark the path with the coordinates:
To make the problem easier, let's say that over the next period of time, the pie drops in 0-10 of these 11 positions. At the beginning Gameboy stood at 5, so in the first second he could only receive a 4,5,6 in one of these three positions. Q. How many pies can Gameboy receive? (assuming his backpack can hold an infinite number of pies)
InputThere are multiple sets of input data. The first behavior of each group of data is a positive integer n (0<n<100000), which indicates that there are n pies falling on the path. In the row of n rows, each row has two integers x,t (0<t<100000), indicating that there is a pie drop at x point in T-second. The same second may drop multiple pies at the same point. N=0 when the input ends.
OutputEach set of input data corresponds to one row of output. Output an integer m, indicating that Gameboy may receive a maximum of M pies.
Tip: The amount of input data in the subject is relatively large, it is recommended to read in scanf, with CIN may time out.
Sample Input65 14 16 17 27 28 30
Sample Output4
Analysis:
This model problem, which moves within a certain range and affects the next step, is the number tower
We make the root of the tree down from the bottom to the top DP at 5.
DP[I][J] I is the position of the 0~10 J for Time
5
4 6
3 5 7
......
AC Code:
1#include <iostream>2 using namespacestd;3 intdp[ A][100005];4 intMaxintXintYintz)5 {6 intm=x;7 if(y>x) m=y;8 return(m>z?)m:z);9 }Ten intMain () One { A intN; - while(SCANF ("%d",&N)) - { the if(n==0) Break; - inttmax=0; -Memset (DP,0,sizeof(DP)); - for(;n>0; n--) + { - intx, y; +scanf"%d%d",&x,&y); Adp[x][y]++; at if(Y>tmax) tmax=y; - } - for(inti=tmax;i>=0; i--) - { - for(intj=0; j<=Ten; j + +) - { in if(j==0) -Dp[j][i]+=max (dp[j][i+1],dp[j+1][i+1]); to Else +Dp[j][i]+=max (dp[j-1][i+1],dp[j][i+1],dp[j+1][i+1]); - } the } *cout<<dp[5][0]<<Endl; $ }Panax Notoginseng return 0; -}
Problem Solving report HDU1176 free pies