HDU 1176 Free Pies (simple DP, number of tower variants)

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 mark the path with the coordinates:

To make the problem easier, let's say that over the next period of time, the pie drops 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. Q. How many pies can Gameboy receive? (assuming his backpack can hold an infinite number of pies) input: There are multiple sets of input data. 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. 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.
Tip: The amount of input data in the subject is relatively large, it is recommended to read in scanf, with CIN may time out.

Sample Input:65-Output:4

This problem is a number of tower variants:

5 i = 0;

5 6 7 i = 1;

4 5 6 7 8 i = 2;

3 4 5 6 7 8 9 i = 3;

2 3 4 5 6 7 8 9 i = 4;

1 2 3 4 5 6 7 8 9 Ten i = 5;

1 2 3 4 5 6 7 8 9 Ten i = 6;

。。。。。。。。。。。。 。。。

State transfer equation: dp[i][j] + = MAX (max (dp[i+1][j-1], dp[i+1][j+1]), dp[i+1][j]);

#include <stdio.h>#include<algorithm>#include<string.h>using namespacestd;Const intn=100010;Const intinf=0x3f3f3f3f;intdp[n][ -];intMain () {intN, I, J, M, X, T;  while(SCANF ("%d", &N) {memset (DP,0,sizeof(DP)); M= -INF;  for(i =1; I <= N; i++) {scanf ("%d%d", &x, &T); M=Max (M, T); Dp[t][x+1]++;///to prevent the array from overstepping, add 1 to each location        }         for(i = M; I >=0; i--)///make time line, position as column        {             for(j =1; J <= One; J + +) Dp[i][j]+ = MAX (max (dp[i+1][j-1], dp[i+1][j+1]), dp[i+1][J]);///only from the left and right to reach the point or at that point does not move, compare the size of the three, take the maximum value} printf ("%d\n", dp[0][6]);///The initial position is 6 and the time is 0.    }    return 0;}

HDU 1176 Free Pies (simple DP, number of tower variants)

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.