Zoj 2972 hurdles of 110 m

Source: Internet
Author: User

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  ;} 

 

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.