Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=1176
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-Output4Pi[i][j] Indicates the number of pies that I get at J at a time, Fall[i][j] indicates the number of pies dropped at I moment J, the state transition equation is pi[i][j] = max (pi[i-1][j-1], pi[i-1][j], pi[i-1][j + 1]) + fall[i][j], and J has a range. Personally think the problem data is not rigorous, the first 4 seconds there is no place to reach, but do not consider still can a.
1#include <iostream>2#include <cstring>3#include <algorithm>4 using namespacestd;5 6 intt, N;7 intpi[100005][ A];8 intfall[100005][ A];9 intans;Ten One intMain () { AIos::sync_with_stdio (false ); - - while(Cin >>N, N) { thememset (PI,0,sizeof(PI)); -Memset (Fall,0,sizeof(Fall)); -Ans =0; -t =0; + - intA, B; + for(inti =0; I < n; i++ ){ ACin >> a >>b; atfall[b][a]++; -t =Max (T, b); - } - -pi[1][4] = fall[1][4]; -pi[1][5] = fall[1][5]; inpi[1][6] = fall[1][6]; - for(inti =2; I <= t; i + +){ to for(intj =0; J <=Ten; J + + ){ + if( ! (i + J >=5&& I-j >=-5) )Continue;//No , I don't think so. A, personal feeling data is not rigorous -PI[I][J] = pi[i-1][j]; the if(J >0) Pi[i][j] = max (Pi[i][j], pi[i-1][j-1] ); * if(J <Ten) Pi[i][j] = max (Pi[i][j], pi[i-1][j +1] ); $PI[I][J] + =Fall[i][j];Panax Notoginseng } - } the + for(inti =0; I <=Ten; i++ ) AAns =Max (ans, pi[t][i]); the +cout << ans <<Endl; - } $ $ return 0; -}
HDU-1176 free Pies (DP)