Hdu4939: Stupid tower defense (DP)

Source: Internet
Author: User
Problem descriptionfsf 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.
Inputthere 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)
 
Outputfor 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 Input
12 4 3 2 1
 
Sample output
Case #1: 12 in optimal conditions, the Red Tower is always at the end. DP [I] [J] indicates that the first one has J blue towers, enumerate the number of the last red tower and the number of the previous blue Tower for DP.
# Include <stdio. h> # include <string. h> # include <algorithm> # include <math. h> using namespace STD; # define up (I, x, y) for (I = x; I <= y; I ++) # define down (I, X, y) for (I = x; I> = y; I --) # define MEM (a, B) memset (a, B, sizeof ()) # define W (x) while (x) # define ll _ int64ll n, x, y, z, T, DP [1505] [1505], SS, CAS = 1, i, J, K, R, ans; int main () {scanf ("% i64d", & SS); W (ss --) {scanf ("% i64d % i64d % i64d % i64d % i64d", & N, & X, & Y, & Z, & T); MEM (DP, 0 ); ans = N * T * x ; // All are red tower up (I, 1, n) Up (J, 0, I) {If (! J) DP [I] [J] = DP [I-1] [J] + T * (i-j-1) * Y; else DP [I] [J] = max (DP [I-1] [J] + (J * z + T) * max (0ll, (i-1-j) * y, DP [I-1] [J-1] + (J-1) * z + T) * (I-j) * Y); ans = max (ANS, DP [I] [J] + (n-I) * (J * z + T) * (x + (I-j) * Y ));} printf ("case # % i64d: % i64d \ n", CAS ++, ANS);} 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.