Free pie time limit: 1000 msmemory limit: 32768 kbthis problem will be judged on HDU. Original ID: 1176
64-bit integer Io format: % i64d Java class name: Main all said that The sky won't drop pies, 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
4
Solution: Convert the time space into a two-dimensional one. DP [I] [J] indicates the maximum pie number obtained by position J of I time.
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <algorithm> 6 #include <climits> 7 #include <vector> 8 #include <queue> 9 #include <cstdlib>10 #include <string>11 #include <set>12 #include <stack>13 #define LL long long14 #define pii pair<int,int>15 #define INF 0x3f3f3f3f16 using namespace std;17 int x,T,m[100100][12],dp[100100][12];18 int main() {19 int n,mT;20 while(scanf("%d",&n),n){21 memset(dp,0,sizeof(dp));22 memset(m,0,sizeof(m));23 mT = 0;24 for(int i = 0; i < n; i++){25 scanf("%d %d",&x,&T);26 ++m[T][x];27 mT = max(mT,T);28 }29 dp[1][4] = m[1][4];30 dp[1][5] = m[1][5];31 dp[1][6] = m[1][6];32 int ans = 0;33 for(int i = 2; i <= mT; i++){34 for(int j = 0; j < 11; j++){35 dp[i][j] = dp[i-1][j];36 if(j > 0) dp[i][j] = max(dp[i][j],dp[i-1][j-1]);37 if(j < 10) dp[i][j] = max(dp[i][j],dp[i-1][j+1]);38 dp[i][j] += m[i][j];39 if(i == mT) ans = max(ans,dp[i][j]);40 }41 }42 printf("%d\n",ans);43 }44 return 0;45 }
View code
HDU 1176 free pie