Hdu4939 stupid tower defense (DP)

Source: Internet
Author: User
Tags cmath

2014 + school 7 second-level questions

4939

Stupid tower defenseTime Limit: 12000/6000 MS (Java/others) memory limit: 131072/131072 K (Java/others) total submission (s): 366 accepted submission (s): 88Problem description FSF is addicted to a stupid tower defense game. the goal of tower Defense Games is to try to stop enemies from crossing a map by building traps to slow them down and towers which shoot at them as they pass.
The map is a line, which has n unit length. we can build only one tower on each unit length. the enemy takes t seconds on each unit length. and there are 3 kinds of tower in this game: The Red Tower, the Green Tower and the blue tower.
The Red Tower damage on the enemy X points per second when he passes through the tower.
The Green Tower damage on the enemy y points per second after he passes through the tower.
The blue tower let the enemy go slower than before (that is, the enemy takes more Z second to pass an unit length, also, after he passes through the tower .) of course, if you are already pass through M green towers, you shoshould have got M * y damage per second. the same, if you are already pass through K blue towers, the enemy shoshould have took T + K * z seconds every unit length.
FSF now wants to know the maximum damage the enemy can get. Input there are multiply test cases.
The first line contains an integer T (t <= 100), indicates the number of cases.
Each test only contain 5 integers n, x, y, z, T (2 <= n <= 1500,0 <= x, y, z <= 60000,1 <= T <= 3) output for each case, You shoshould output "case # C:" First, where C indicates the case number and counts from 1. then output the answer. for each test only one line which have one integer, the answer to this question. sample input12 4 3 2 1 sample outputcase #1: 12HintFor the first sample, the first tower is blue tower, and the second is Red Tower. so, the total damage is 4*(1 + 2) = 12 damage points. authoruestc source 2014 multi-university training contest 7 recommendwe have carefully selected several similar problems for you: 4944 4943 4942 4941 4940

Question:Tower guard, it's strange that the initial time for each block is T. A tower can be built for each piece. There are three types of towers. One is the red tower, and the other is X output per second when it passes through the current grid. The other is a green Tower, which is attacked by virus Y every second after it passes through the current grid; one is the blue tower. The time that passes through the current grid increases by Z seconds. The Green Tower and the blue tower can be combined to find the highest output.

Problem: DP.

Thinking questions, you can think of the red tower to put the last is the optimal solution, you can prove: if there is a red tower behind the red tower, exchange them will certainly have a better solution.

In this way, we will enumerate the number of non-red towers and the number of green towers. f [I] [J] indicates that there are I non-red towers in front of them, and when there are j green towers, the blue-green tower outputs and in the whole road section.

Because I and j are known, the output of the red tower behind them is also fixed (only as I and j change, and the output of the Red Tower remains unchanged when IJ Is fixed ), therefore, we use DP to obtain the largest f [I] [J] of various IJ, and ANS update each time.

Because the number seems to be a little large, it is better to use a queue that will be rolled out with a super commit.

1 // # pragma comment (linker, "/Stack: 102400000,102400000 ") 2 # include <cstdio> 3 # include <cmath> 4 # include <iostream> 5 # include <cstring> 6 # include <algorithm> 7 # include <cmath> 8 # include <map> 9 # include <set> 10 # include <stack> 11 # include <queue> 12 using namespace STD; 13 # define ll long long14 # define usll unsigned ll15 # define MZ (array) memset (array, 0, sizeof (array) 16 # define minf (array) memset (ARR Ay, 0x3f, sizeof (array) 17 # define rep (I, n) for (I = 0; I <(n); I ++) 18 # define for (I, X, n) for (I = (x); I <= (n); I ++) 19 # define RD (X) scanf ("% d", & X) 20 # define RD2 (x, y) scanf ("% d", & X, & Y) 21 # define rd3 (x, y, z) scanf ("% d", & X, & Y, & Z) 22 # define Wn (X) prllf ("% d \ n", x); 23 # define re freopen ("D. in "," r ", stdin) 24 # define we freopen (" 1biao. out "," W ", stdout) 25 ll max (ll x, ll y) {26 return x> Y? X: Y; 27} 28 ll f [2] [1555] [1555]; // green blue29 30 int main () {31 ll t, CAS = 1; 32 ll N, T; 33 ll x, y, z; 34 ll now, pre; 35 ll I, j, k; 36 scanf ("% i64d", & T ); 37 while (t --) {38 scanf ("% i64d % i64d % i64d % i64d", & N, & X, & Y, & Z, & T ); 39 memset (F, 0, sizeof (f); 40 now = 0; 41 pre = 1; 42 ll ans = x * T * n; 43 for (I = 1; I <= N; I ++) {// 1st to the 44 for (j = 0; j <= I; j ++) {// 1st to I have J green45 K = I-j; // 1st to I have k blue46 if (k> 0) {// 47 F [now] [J] [k] = f [pre] [J] [k-1] + J * y * z *( n-I ); /// put this blue. The next n-I lattice increases the Z time by 48} 49. If (j> 0) {// Green 50 F [now] [J] [k] = max (F [now] [J] [K], f [pre] [J-1] [k] + y * (t + K * z) * (N-I )); /// add y damage every second when you put this green color. 51} 52 ans = max (ANS, F [now] [J] [k] + x * (N-I) * (t + K * z); 53} 54 pre = now; 55 now ^ = 1; 56} 57 printf ("case # % i64d: % i64d \ n ", CAS ++, ANS); 58} 59 return 0; 60}
View code

 

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.