HDU 4939 stupid tower defense (DP)

Source: Internet
Author: User

Question Link

A straight line with N unit lengths is given. Every passing through a unit length takes t s.

There are three types of towers. The Red Tower can cause X points of damage per second in the current lattice. The Green Tower can cause y points of damage per second in the subsequent lattice. The blue tower can increase the length of time by Z seconds. Ask how to arrange the sequence of the Three Towers to maximize the damage and output the maximum damage value.

Analysis: During the competition, we didn't really think of three different towers. Each of them has different roles. You only need to know the problem.

All the red towers are placed at the end, because the length of the straight line is certain, and the Red Tower will not increase the damage behind it. Then the question is how to arrange it.

Green Tower and blue tower, I am here d [I] [J] represents the first I straight line, put the maximum value of J Green Tower (it seems that many people like to write and put the blue tower, but it is the same ).

1 # include <iostream> 2 # include <cstdio> 3 # include <cstring> 4 # include <cstdlib> 5 # include <algorithm> 6 # define ll _ int64 7 const int maxn = 1500 + 10; 8 using namespace STD; 9 LL d [maxn] [maxn]; 10 11 int main () 12 {13 int T, CA = 1; 14 LL n, x, y, z, T, I, J; 15 ll ans, RET; 16 scanf ("% d", & T); 17 while (t --) 18 {19 scanf ("% i64d % i64d % i64d % i64d", & N, & X, & Y, & Z, & T); 20 ret = 0; 21 memset (D, 0, sizeof (D); 22 ret = N * x * t; // At the beginning, if the number is less than the number, it is the red tower. It is wrong many times, because I wrote n-I; 23 for (I = 1; I <= N; I ++) 24 {25 for (j = 0; j <= I; j ++) 26 {27 ll TMP = 0; 28 If (J! = I) 29 d [I] [J] = d [I-1] [J] + y * j * (t + z * (i-j-1 )); // put blue tower 30 on the I th if (J! = 0) 31 TMP = d [I-1] [J-1] + y * (J-1) * (t + z * (I-j )); // put the green tower 32 33 d [I] [J] = max (TMP, d [I] [J]) in the I stage; 34 ans = d [I] [J] + (x + y * j) * (t + z * (I-j) * (N-I ); // Add the following damage 35 if (ANS> RET) 36 ret = ans; 37} 38} 39 printf ("case # % d: % i64d \ n ", CA ++, RET); 40} 41 return 0; 42}

 

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.