Free pie (hdu 1176 simple DP), hdu1176

Source: Internet
Author: User
Tags acos

Free pie (hdu 1176 simple DP), hdu1176

Free pie Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission (s): 28519 Accepted Submission (s): 9737


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 Input
65 14 16 17 27 28 30
 
Sample Output
4
 
Authorlwg
RecommendWe have carefully selected several similar problems for you: 1003 1058 1203 1257 1421
Question: 0 ~ 10 A total of 11 coordinates, now there are n pie in the 11 position, tell each pie falling time t and coordinate x, and located in x can only catch the X-1, the pie in the three positions of x, x + 1 asked how many pies can be caught.

Idea: dp [I] [j] indicates the maximum number of pies that can be caught at x at I. The dp is initialized to 0. First, calculate the number of pies in the j position at the time of I. This way, it turns into a number tower problem. You can change the time to DP, the final answer is dp [0] [5]. You can also proceed. The final answer is dp [T] [0 ~ The maximum value in 10] (T is the maximum time). When you start, you must control the starting point from 5.

Code:

// Shift by time # include <iostream> # include <cstdio> # include <cstring> # include <algorithm> # include <cmath> # include <string> # include <map> # include <stack> # include <vector> # include <set> # include <queue> # define maxn 100010 # define MAXN 2005 # define mod 1000000009 # define INF 0x3f3f3f # define pi acos (-1.0) # define eps 1e-6 # define lson rt <1, l, mid # define rson rt <1 | 1, mid + 1, r # define FRE (I, a, B) for (I = a; I <= B; I ++) # define FRL (I, a, B) for (I = a; I <B; I ++) # define mem (t, v) memset (t), v, sizeof (t) # define sf (n) scanf ("% d", & n) # define sff (a, B) scanf ("% d", & a, & B) # define sfff (a, B, c) scanf ("% d", & a, & B, & c) # define pf printf # define DBG pf ("Hi \ n") typedef long ll; using namespace std; int dp [maxn] [12]; int main () {int I, x, t; int n; while (sf (n) & n) {mem (dp, 0); int T =-1; FRL (I, 0, n) {sff (x, t); dp [t] [x] ++; // record T = max (T, t); // Record maximum time} for (I = T; I> = 0; I --) // roll back by time {dp [I] [0] + = max (dp [I + 1] [0], dp [I + 1] [1]); for (int j = 1; j <10; j ++) dp [I] [j] + = max (dp [I + 1] [J-1], dp [I + 1] [j]), dp [I + 1] [j + 1]); dp [I] [10] + = max (dp [I + 1] [9], dp [I + 1] [10]);} pf ("% d \ n", dp [0] [5]);} return 0 ;}



// Start with # include <iostream> # include <cstdio> # include <cstring> # include <algorithm> # include <cmath> # include <string> # include <map> # include <stack> # include <vector> # include <set> # include <queue> # define maxn 100010 # define MAXN 2005 # define mod 1000000009 # define INF 0x3f3f3f # define pi acos (-1.0) # define eps 1e-6 # define lson rt <1, l, mid # define rson rt <1 | 1, mid + 1, r # define FRE (I, a, B) for (I = a; I <= B; I ++) # define FRL (I, a, B) for (I = a; I <B; I ++) # define mem (t, v) memset (t), v, sizeof (t) # define sf (n) scanf ("% d", & n) # define sff (a, B) scanf ("% d", & a, & B) # define sfff (a, B, c) scanf ("% d", & a, & B, & c) # define pf printf # define DBG pf ("Hi \ n") typedef long ll; using namespace std; int dp [maxn] [12]; int main () {int I, x, t; int n; while (sf (n) & n) {mem (dp, 0); for (I = 0; I <12; I ++) dp [0] [I] =-INF; dp [0] [5] = 0; // The control start point starts from 5 and int T =-1; FRL (I, 0, n) {sff (x, t ); dp [t] [x] ++; T = max (T, t) ;}for (I = 1; I <= T; I ++) // by time {dp [I] [0] + = max (dp [I-1] [0], dp [I-1] [1]); for (int j = 1; j <10; j ++) dp [I] [j] + = max (dp [I-1] [J-1], dp [I-1] [j]), dp [I-1] [j + 1]); dp [I] [10] + = max (dp [I-1] [9], dp [I-1] [10]);} int ans =-1; for (I = 0; I <= 10; I ++) // obtain the maximum value ans = max (ans, dp [T] [I]); pf ("% d \ n", ans);} 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.