Main topic
The game interface is a two-dimensional plane with a length of N and a height of M, with a K-pipe (ignoring the width of the pipe). The bird always moves within the game's interface. The bird starts at the leftmost integer height of the game interface and reaches the far right of the game interface, completing the game. Birds each unit time along the horizontal axis to the right of the distance is 1, vertical movement of the distance is controlled by the player. If you click on the screen, the bird will rise a certain height x, each unit time can be clicked multiple times, effect overlay; If you do not tap the screen, the bird will drop a certain height y. When the birds are in different positions in the horizontal axis, the ascending height x and the descending height y may differ from each other. The bird height is equal to 0 or the bird hits the pipe and the game fails. When the bird height is m, it can no longer rise. Now, tell me if you can finish the game. If you can, output a minimum number of hits on the screen, otherwise, the output bird can pass the maximum number of pipe gaps.
Exercises
The simplest of the rules is the definition of $f (I,J) $ for the first $i$ time, the height of the $j$ when the minimum number of ascending steps, transferred to Updmin$f (I+1,j-y_i), F (i,j) +1$,updmin$f (i+1,j+kx_i), F (i,j) +k$. Such time complexity is however for $o (nm^2) $, which cannot AC. How are we going to get rid of that $k$? We can think of this: for each $j$, at the current moment $t$, we first point the screen once, the bird moved to the next time $t ' $, then you can casually dot the screen let the bird in time $t ' $ in the constant rise, to update the other height of the dynamic rules. This can be seen in the $t ' $, the height as a backpack capacity, the volume of the goods is $x_t$, the value of $1$, the value of the $f (T ', j) $, each item at least one of the complete backpack.
Attention:
The
- is updated by x and updated by Y, because when the x is updated, it must meet the conditions of the continuous location screen, and if Y is in front of it, it may cause the bird to drop before the screen lets the bird go up in the $t ' $, which is not test instructions.
- We just need to update the table only by the legal state, and later J if it's inside the pipe, we don't have to. On the one hand to save code, on the other hand the full backpack update will also need to fly to the answer in the pipeline.
- in case the point screen is stuck at the top of the screen, swipe down from the border.
#include <cstdio> #include <cstring> #include <algorithm>using namespace std; #define Updatemin (x, y) x = min (x, y) const int max_len = 10010, Max_h = 1010 * 2, Max_col = Max_len, INF = 0x3f3f3f3f;int Totlen, TotH, Totcol;int R Iselen[max_len], Declen[max_len];int High[max_len], Low[max_len];bool reacht;int ans;void DP () {static int F[2][MAX_COL ]; memset (F[0], 0, sizeof (f[0)); int passcnt = 0; for (int i = 0; i < Totlen; i++) {bool Noans = true; int top = min (TotH, high[i]-1), top2 = min (TotH, High[i + 1]-1); for (int h = low[i] + 1, h <= min (TotH, high[i]-1), h++) {if (F[i & 1][h] < INF) {Noans = false; Break }} if (Noans) {Ans = passcnt; Return } if (High[i] < INF) passcnt++; memset (F[i + 1 & 1], INF, sizeof (F[i + 1 & 1])); for (inth = low[i] + 1; H <= top; h++) Updatemin (f[i + 1 & 1][h + riselen[i]], F[i & 1][h] + 1); for (int h = 1; h <= top2; h++) updatemin (f[i + 1 & 1][h + riselen[i]], F[i + 1 & 1][h] + 1); for (int h = max (Low[i] + 1, declen[i] + 1), H <= top; h++) updatemin (f[i + 1 & 1][h-declen[i], f[i & 1][h]); if (high[i + 1] = = INF) for (int dh = 1; DH <= riselen[i]; dh++) updatemin (f[i + 1 & 1][t OtH], F[i + 1 & 1][toth + DH]); } Ans = INF; for (int h = 1; h <= TotH; h++) updatemin (Ans, F[totlen & 1][h]); if (ans = = INF) ans = passcnt; else Reacht = true;} int main () {scanf ("%d%d%d", &totlen, &toth, &totcol); for (int i = 0; i < Totlen; i++) scanf ("%d%d", Riselen + i, Declen + i); memset (High, INF, sizeof); for (int i = 0; i < Totcol; i++) {int p, n, high; scanf ("%d%d%d", &amP;p, &low, &high); HIGH[P] = high; LOW[P] = low; } DP (); printf ("%d\n%d\n", Reacht, Ans); return 0;}
luogu1941 Flying Birds