ACM Hangzhou Power Special Topic 31,007

Source: Internet
Author: User
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 give this path such as the coordinates of the icon: <br><center></center><br> in order to simplify the problem, suppose that in the next period of time, the pie will fall 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. Ask Gameboy How many pies may be received at most. (assuming his backpack can hold an infinite number of pies) <br>
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. <br>
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. <br> tip: The amount of input data in the subject is relatively large, it is recommended to read in scanf, with CIN may time out. <br><br>
Sample Input
6 5 1 4 1 6 1 7 2 7 2 8 3 0
Sample Output
4 (1) The main idea: because it is a Chinese topic, no more say. Is that a person in a one-dimensional coordinate to pick up the cake. (2) Ideas:   can draw a graph, a two-dimensional array, then, there is a pie Mark 1, the other is 0, so, it is also important to note that the final should be compared and accumulated from the backward (because the solution is from the last to receive the coordinates of the pie, Time Forward Sums) (3) Sentiment: In general, in my There are greedy thoughts, because every move, you have to consider the most cake, every step to judge. Also, is the scope of the array is very critical, small will be saved, running error, change a little bit better. (4) #include <iostream> #include <cstdio> #include <cstring> int dp[100001][11]; int max (int x, int y, int z) { if (x>y)   if (x>z)    return x;   else &nbs P;  return Z;  else   if (y>z)    return y;   else    return Z; } using namespace Std; int main () { int n, I, J, X, T, K;  while (cin>>n && n! = 0)  {  memset (DP, 0, SI Zeof (DP));   k = 0;   for (i = 0;i<n;i++)   {   cin >> x;    cin >> t; &nbs p;  dp[t][x]++;    if (t>k)     k = t;   }   for (i = k-1;i >= 0;i--)   {   for (j = 0;j<11;j++)    {  &nbsp ;  if (j>0 && j<10)      dp[i][j] + + max (dp[i + 1][j-1], Dp[i + 1][j], Dp[i + 1][j + 1]);     else if (j = = 0)      dp[i][j] + + max (0, Dp[i + 1][j], dp[i + 1][j + 1]);     else      dp[i][j] + = max (0, Dp[i + 1][j-1], dp[i + 1][j]);    }   }   cout << dp[0][5] << Endl;  }  return 0; }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.