Description said the sky will not drop pies, but one day Gameboy is walking home on the path, suddenly the sky fell 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 in this position, so in the first second he could only receive a 4,5,6 in the middle of this three position. Q. How many pies can Gameboy receive? (assuming his backpack can hold an infinite number of pies) input data has multiple groups. The first behavior of each group of data is a positive integer n (0 < n < 100000), indicating that n pies fall on this 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. Output each set of input data corresponds to a row of outputs. 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 Input
65 14 16 17 27 28 30
Sample Output
4
HINT
DP three elements: initial state, state equation, boundary
#include <cstdio>#include<cstring>#include<algorithm>using namespacestd;Const intMAX =110000;intdp[max][ A];intMain () {intn,x,t,t1; T1=0; while(~SCANF ("%d", &n) &&N) {memset (DP,0,sizeof(DP)); for(inti =1; I <= n;i++) {scanf ("%d%d",&t,&x); Dp[x][t]++; if(T1 < T) T1 =T; } for(inti = t1; I >=0; i--) {dp[i][0] + = max (dp[i+1][1],dp[i+1][0]); for(intj =0; J <=Ten; J + +) {Dp[i][j]+ = MAX (max (dp[i+1][j],dp[i+1][j+1]), dp[i+1][j-1]); }} printf ("%d\n", dp[0][5]); } return 0;}
View Code
dp--Free Pies