Free pie
Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 26290 accepted submission (s): 8952
Problem description all said there would be no pie in the sky, but one day Gameboy was walking on the path home, And suddenly there were 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)
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.
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
65 14 16 17 27 28 30
Sample output
4dp [I] [J] indicates the maximum number of pies in the J position of the I second. From the maximum time point to the zero time point, DP [0] [5] is the answer. Transition equation DP [I] [J] + = max (DP [I + 1] [J], DP [I + 1] [J + 1]) J = 0; + = max (DP [I + 1] [J], DP [I + 1] [J-1]) J = 10; + = max (DP [I + 1] [J], DP [I + 1] [J-1], DP [I + 1] [J + 1]) J! = 0 & J! = 10#include <iostream>#include <cstdio>#include <algorithm>#include <set>#include <cctype>#include <cstring>#include <string>#include <vector>#include <stack>#include <queue>using namespace std;const int maxn=100010;const int INF=0x3f3f3f3f;int dp[maxn][11],n,max_time;int three_max(int x,int y,int z){return max(x,max(y,z));}void solve(){for(int i=max_time-1;i>=0;i--){for(int j=0;j<=10;j++){if(j==0)dp[i][j]+=max(dp[i+1][j],dp[i+1][j+1]);else if(j==10)dp[i][j]+=max(dp[i+1][j],dp[i+1][j-1]);elsedp[i][j]+=three_max(dp[i+1][j-1],dp[i+1][j],dp[i+1][j+1]);}}printf("%d\n",dp[0][5]);}int main(){int x,T; while(scanf("%d",&n)!=EOF&&n){memset(dp,0,sizeof(dp));max_time=-INF;for(int i=0;i<n;i++){scanf("%d%d",&x,&T);++dp[T][x];max_time=max(max_time,T);}solve();} return 0;}
HDU 1176-free pie (DP _ Reverse push)