A problem that feels pretty pit.
Test instructions is much like a game called "the man under the 100 floor". But a time limit is required to fall from one point to the ground within a limited time. There is also a maximum drop height, a maximum fall so high, or will fall dead.
First think of DP, and then think of a half-day unexpected state, because if the following placement status, a board will have a lot of state, and then can not go on.
Then try to prove the greed, the results prove not come out. Greed can not be used.
Actually gave up, at the end of the game and then went to see, and then discussed, then bar Bar ... Still can't do it. The result was a search for a puzzle, alas, a sense of frustration.
Input:
The first line enters the integer t, which represents the common T Group data.
Next, enter N, x, H, MAXN, M for the first row of each group of data. respectively, the number of boards, the initial position of the horizontal axis, the height of the initial position, the maximum time can fall height, limited time.
Next n rows, 3 integers per line, L, R, H. Represents the left side of the first board, the left side of the right, the height.
Output:
If within m seconds (including m seconds) can reach the ground, output "NO", otherwise output "YES".
The solution is still DP, but he slightly turned a bend, set the state is the left of each board and the right side of the coordinates, so that the fall from different high board to the same low board will produce a different state of the problem, have to sigh, DP really magical.
Core--judging from the first block of the board on the left, the right end of the drop to block J Board of the left, the right end (if possible) is better than the original section J board the left and the end of the time.
1#include <cstdio>2#include <cmath>3#include <cstring>4#include <algorithm>5#include <queue>6 using namespacestd;7 8 Const intN =1010;9 Ten structTp One { A intL, R, H; - }tp[n]; - the intdp[n][2]; - intx, Maxn, H; - intN, M, T; - + BOOLCMP (TP x, tp y) - { + returnX.h >Y.h; A } at - voidInit () - { -scanf"%d%d%d%d%d", &n, &x, &h, &MAXN, &m); -tp[0].L = x; tp[0].R = x; tp[0].h = h;//starting point is also set as a board, the left and right side are X, height is h - for(inti =1; I <= N; i++) in { -scanf"%d%d%d", &TP[I].L, &TP[I].R, &tp[i].h); to } +tp[n+1].L =-1; tp[n+1].R = N; tp[n+1].h =0;//Ground -Sort (TP, tp+n+1, CMP);//Sort, save time for a large break in the back thedp[0][0] = dp[0][1] =0;//Initial State * for(inti =1; I <= n+1; i++) $ {Panax Notoginsengdp[i][0] = dp[i][1] =1000010; - } the } + A voidDp () the { + for(inti =0; I <= N; i++) - { $ BOOLP1 =0, p2 =0; $ for(intj = i+1; J <= n+1; J + +)//on J falling from I - { - if(Tp[i].h-tp[j].h > MAXN) Break;//If you fall to death, go to the next I board. the - if(TP[I].L >= tp[j].l && tp[i].l <= tp[j].r &&!p1)//If I can fall from the left of I to J.Wuyi { theP1 =1;//I can only fall on the left side of a fixed board, can not fall to two boards - if(J! = n+1)//If you do not fall to the ground, you need to calculate the longitudinal displacement time and the lateral displacement time Wu { -dp[j][0] = min (dp[j][0], dp[i][0]+tp[i].h-tp[j].h+tp[i].l-tp[j].l); Aboutdp[j][1] = min (dp[j][1], dp[i][0]+tp[i].h-tp[j].h+tp[j].r-tp[i].l); $ } - Else //to the ground, you do not need to calculate the lateral displacement time - { -dp[j][0] = min (dp[j][0], dp[i][0]+tp[i].h-tp[j].h); Adp[j][1] = min (dp[j][1], dp[i][0]+tp[i].h-tp[j].h); + } the } - if(TP[I].R >= tp[j].l && tp[i].r <= tp[j].r &&!p2)//If I can fall from the right end of I to J. $ { theP2 =1;//I the right end of the same can only fall on a fixed board, can not fall to two boards the if(J! = n+1) the { thedp[j][0] = min (dp[j][0], dp[i][1]+tp[i].h-tp[j].h+tp[i].r-tp[j].l); -dp[j][1] = min (dp[j][1], dp[i][1]+tp[i].h-tp[j].h+tp[j].r-TP[I].R); in } the Else the { Aboutdp[j][0] = min (dp[j][0], dp[i][1]+tp[i].h-tp[j].h); thedp[j][1] = min (dp[j][1], dp[i][1]+tp[i].h-tp[j].h); the } the } + } - } the }Bayi the voidoutput () the { - if(dp[n+1][0] <= m | | dp[n+1][1] <= m) printf ("no\n"); - Elseprintf"yes\n"); the } the the intMain () the { - //freopen ("Test.txt", "R", stdin); thescanf"%d", &t); the while(t--) the {94 init (); the Dp (); the output (); the }98 return 0; About}
View Code
HDU 2155 Small Black Town soul song (DP)