Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=1176
Free pies
Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 38193 Accepted Submission (s): 13056
Problem description said the sky will not drop pies, but one day Gameboy is walking on the path home, 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, 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)
Input data has multiple groups. 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.
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 Input65 14 16 17 27 28 30
Sample Output4 The second time, the idea of the first time can not remember ... Input z (coordinates), T (moment), ABS (Z-5) <t indicates that the point of the pie at that time must not be received, it does not exist. State transitions:
for(intI=1; i<=maxt; i++) for(intj=0; j<=Ten; J + +) { if(j==0) Dp[i][j]=max (dp[i-1][j],dp[i-1][j+1])+Pai[j][i]; Else if(j==Ten) Dp[i][j]=max (dp[i-1][j-1],dp[i-1][J]) +Pai[j][i]; ElseDp[i][j]=max (Max (dp[i-1][j-1],dp[i-1][J]), dp[i-1][j+1])+Pai[j][i]; }
dp[100005 (i)][15 (j)] indicates the maximum value of the pie at Point J when the second is first.
Quite with the complexity of using 1e7 to forget all the situation.
See online said is a simple tower, although do not know what is, but from the DP update can understand some meaning.
Be aware of the update of the DP at each moment, the value of the point that cannot be reached at that moment must be zero.
#include <iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<stdlib.h>using namespacestd;#defineMaxt 100005intdp[100005][ the];intpai[ the][100005];intMain () {intn,z,t; while(SCANF ("%d", &n)!=eof&&N) {memset (Pai,0,sizeof(PAI)); Memset (DP,0,sizeof(DP)); for(intI=0; i<n; i++) {scanf ("%d%d",&z,&t); if(ABS (Z-5) <=t) pai[z][t]++; } for(intI=1; i<=maxt; i++) for(intj=0; j<=Ten; J + +) { if(j==0) Dp[i][j]=max (dp[i-1][j],dp[i-1][j+1])+Pai[j][i]; Else if(j==Ten) Dp[i][j]=max (dp[i-1][j-1],dp[i-1][J]) +Pai[j][i]; ElseDp[i][j]=max (Max (dp[i-1][j-1],dp[i-1][J]), dp[i-1][j+1])+Pai[j][i]; } intres=0; for(intI=0; i<=Ten; i++) { if(dp[maxt][i]>Res) Res=Dp[maxt][i]; } printf ("%d\n", RES); } return 0;}
View Code
hdu_1176_ free pie _16.4.23 do again