Free DP dish pie

Source: Internet
Author: User
Free pie

Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/others) total submission (s): 26427 accepted submission (s): 8998

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 input65 14 16 17 27 28 30

 

Sample output4
1 # include <stdio. h> 2 # include <stdlib. h> 3 # include <string. h> 4 int n, x, t, DP [100005] [15]; 5 Int Max _ (int A, int B) 6 {7 Return (A> = B )? A: B; 8} 9 int main () 10 {11 int I, j, A, B, maxt, Max; 12 while (scanf ("% d ", & N), n) 13 {14 maxt = 0; 15 memset (DP, 0, sizeof (DP); 16 for (I = 1; I <= N; I ++) 17 {// every second is regarded as a layer, which means 18 scanf ("% d", & A, & B) as the same as that of the tower ); 19 DP [B] [A + 1] + = 1; 20 if (B> maxt) maxt = B; // upper bound 21} 22 for (I = maxt; i> = 0; I --) 23 {24 for (j = 1; j <= 11; j ++) 25 {// The current state depends on his substate 26 dp [I] [J] + = max _ (DP [I + 1] [J-1], DP [I + 1] [J]), DP [I + 1] [J + 1]); 27} 28} 29 printf ("% d \ n ", DP [0] [6]); // forget to consider the Starting Point 30} 31 return 0; 32}
View code

 

Free DP dish pie

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.