Question: In the 110-meter column, athletes can run in three states: 1. The State consumes physical strength and runs fast. 2. The State does not consume physical strength. 3. The State recovers physical strength and runs slowly.
The maximum physical strength is m, and the initial physical strength is full. Now I want to know the minimum time to complete the process.
Analysis: DP, full backpack. The subject is a backpack with a negative volume. You can find a backpack.
However, because the size of an item may be negative, no matter which direction of the backpack has a suffix, directly use two-dimensional to avoid the suffix.
Transfer equation: f (I, j) = min (f (i-F1, j) + T1, F (I-1, j) + T2, f (I + F2, J) + T3 ).
Note ).
# Include <iostream> # include <cstdlib> using namespace STD; int f [111] [111]; int T1 [111]; int T2 [111]; int t3 [111]; int F1 [111]; int F2 [111]; int dp (int n, int m) {for (INT I = 0; I <= N; ++ I) for (Int J = 0; j <= m; ++ J) f [I] [J] = 0 xffffff; For (INT I = 0; I <= m; ++ I) f [0] [I] = 0; For (INT I = 1; I <= N; ++ I) {/* First State */For (Int J = F1 [I]; j <= m; ++ J) if (j <= M & F [I] [j-F1 [I]> F [I-1] [J] + T1 [I]) f [I] [j-F1 [I] = f [I-1] [J] + T1 [I];/* Second State */For (Int J = 0; j <= m; ++ J) if (F [I] [J]> F [I-1] [J] + T2 [I]) f [I] [J] = f [I-1] [J] + T2 [I];/* Third State */For (Int J = 0; j <= m; + + J) if (F [I] [min (J + F2 [I], M)]> F [I-1] [J] + T3 [I]) f [I] [min (J + F2 [I], M)] = f [I-1] [J] + T3 [I];} int min = 0 xffffff; for (INT I = 0; I <= m; ++ I) if (min> F [N] [I]) min = f [N] [I]; return min;} int main () {int t, n, m; while (CIN> T) while (t --) {CIN> N> m; for (INT I = 1; I <= N; ++ I) cin> T1 [I]> T2 [I]> t3 [I]> F1 [I]> F2 [I]; cout <dp (n, m) <Endl;} return 0 ;}
Zoj 2972-hurdles of 110 m