HDU 1176 free pie (DP)

Source: Internet
Author: User
HDU 1176 free pie

Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1176

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 input6 5 1 4 1 6 1 7 2 7 2 8 3 0

Sample output4

 

Analysis: d [I] [J] indicates the optimal value of the I-second and J-position. dynamic transfer equation: d [I] [J] = max (d [I + 1] [J-1], d [I + 1] [J], d [I + 1] [J + 1])

 

Code:

# include
using namespace STD;
int DP [100010] [12];
int max (int A, int B, int c)
{< br> A = A return a }< br> int main ()
{< br> int t, x, N, I, j;
while (~ Scanf ("% d", & N), n)
{< br> memset (DP, 0, sizeof (DP);
int maxt = 0;
for (I = 0; I {< br> scanf ("% d", & X, & T );
DP [T] [x + 1] ++;
If (maxt maxt = T;
}< br> for (I = maxt; I> = 0; I --)
for (j = 1; j <= 11; j ++)
DP [I] [J] + = max (DP [I + 1] [J-1], DP [I + 1] [J], DP [I + 1] [J + 1]);
printf ("% d \ n", DP [0] [6]);
}< br> 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.