Zoj 2972-hurdles of 110 m

Source: Internet
Author: User

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

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.