hdoj-1176-Free Pies __algorithm

Source: Internet
Author: User
Free Pies Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 26090 accepted Submission (s): 8896


Problem Description said the sky will not drop pie, but one day Gameboy is walking on the way home, suddenly fell a lot of pie in the sky. Said Gameboy's character is very good, the pie does not drop elsewhere, it fell to his side of the 10 meters range. If the pie fell on the ground of course can not eat, so Gameboy immediately unloaded the backpack to pick up. But because he could not stand on either side of the path, he could only pick up the path. Because Gameboy usually stays in the room to play the game, although in the game is a skill Agile master, but in the reality motor nerves are particularly dull, each second species only in move not more than a metre of the range to catch the falling pie. Now give the path the coordinates of the icon:

To simplify the problem, suppose that over the next period of time, the Pies fall to 0-10 of the 11 locations. Gameboy stood at 5 at the start, so in the first second, he could only receive a pie in one of 4,5,6 's three locations. Ask Gameboy How many pies can be received. (assuming his backpack can hold an infinite number of pies)

Input data has multiple groups. The first behavior of each set of data is a positive integer n (0<n<100000), which means that n pies fall on the path. In the n rows, each row has two integers x,t (0<t<100000), indicating that a pie was dropped at x point in T seconds. One second at the same point may fall off multiple pies. N=0 when the input ends.

Output per group of input data corresponds to one row of outputs. Output an integer m, which means that Gameboy can receive up to M pie.
Tip: The amount of input data is large, it is recommended to read in scanf, with CIN may time out.


Sample Input
6 5 1 4 1 6 1 7 2 7 2 8 3-0
Sample Output
4
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int dp[100010][12];
int main ()
{
    int n,x,i,j,t,m;
    while (scanf ("%d", &n) &&n)
    {
        memset (dp,0,sizeof (DP));
        m=0; 
        while (n--)
        {
            scanf ("%d%d", &x,&t);
            dp[t][x]++;
            if (m<t)
            {
                m=t;      Find the longest time point
            }} for
        (i=m-1 i>=0; i--)
        {
            dp[i][0] = max (dp[i+1][0],dp[i+1][1));
            For (J=1 j<=10; j + +)
            {
                 Dp[i][j] = max (max (dp[i+1][j],dp[i+1][j+1)), dp[i+1][j-1])
            ; 
        printf ("%d\n", Dp[0][5]);    0 seconds of the initial position of the site
    } 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.