Http://acm.zju.edu.cn/onlinejudge/showProblem.do? Problemcode = 2972.
In the beginning, I thought it was a type of question similar to jiashuo. But the difference between this question and jiashuo is that each section has a speed value, which indicates that the state of jiashuo is a bit complicated.
Therefore, it is a little simpler.
DP [I] [J] indicates that the force of J is left when J is reached in segment I.
Therefore, it is clear that according to the question:
Stateful transition equation:
DP [I] [J] = min (DP [I-1] [J] + T2, DP [I] [J]);
If (j> = F1)
DP [I] [j-f1] = min (DP [I-1] [J] + T1, DP [I] [j-f1]);
Int temp = J + F2;
If (temp> m) temp = m;
DP [I] [temp] = min (DP [I] [temp], DP [I-1] [J] + T3 );
View code
# Include <iostream> # Include < String . H> # Include <Algorithm> # Include <Stdio. h> # Define Maxn 200 Using Namespace STD; Const Int INF = 10000 ; Int DP [maxn] [maxn]; Int Main (){ Int Test; Int N, m; Int T1, T2, T3, F1, F2; For (CIN> test; test -- ) {CIN >>N> M; fill (DP [ 0 ], DP [n + 1 ], INF ); // Attention should be paid to fill Functions DP [ 0 ] [M] = 0 ; For ( Int I = 1 ; I <= N; I ++ ) {CIN > T1> T2> T3> F1> F2; For ( Int J = m; j> = 0 ; J -- ) {DP [I] [J] = Min (DP [I- 1 ] [J] + T2, DP [I] [J]); // Normal Mode If (J> = F1) DP [I] [J -F1] = min (DP [I-1 ] [J] + T1, DP [I] [j-f1]); // Sufficient effort and maximum speed Int Temp = J + F2; If (Temp> m) temp = m; // The maximum value cannot be exceeded. DP [I] [temp] = min (DP [I] [temp], DP [I- 1 ] [J] + T3 ); // Slowest effort } Cout <* Min_element (DP [N], DP [N] + M + 1 ) <Endl;// Pay attention to this function } Return 0 ;}