hdu 4939 Stupid Tower Defense(DP)2014多校训练第7场

Stupid Tower Defense

                                                                        Time Limit: 12000/6000 MS (Java/Others)    Memory Limit:
131072/131072 K (Java/Others)

Problem 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 should have got m*y damage per second. The same, if you are already pass through k blue towers, the enemy should 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 should 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

1
2 4 3 2 1

Sample Output

Case #1: 12

Hint

For 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.

题意:给出一条长为n个单位长度的直线,每通过一个单位长度需要t秒。

有3种塔,红塔可以在当前格子每秒造成x点伤害,绿塔可以在之后的格子每秒造成y点伤害,蓝塔可以使通过单位长度的时间增加z秒。问如何安排3种塔的顺序使得造成的伤害最大,输出最大伤害值。

分析:如果要安排红塔,则红塔在前面没有在后面造成的伤害大。所以可以枚举红塔的数量i,对前n-i座塔进行dp。

设dp[i][j]表示前i个单位长度中有j个蓝塔造成的最大伤害,则

dp[i][j] = max(dp[i-1][j-1] + (i - j) * y * (t + (j - 1) * z),  dp[i-1][j] + (i - j - 1) * y * (t + j * z))

其中,(i - j) * y * (t + (j - 1) * z)表示i-j个绿塔在第i 个格子造成的伤害,(i - j - 1) * y * (t + j * z)表示i-j-1个绿塔在第i个格子造成的伤害。

求出dp[i][j]以后,则红塔数量为n-i时的总伤害为damage=dp[i][j] + (n - i) * x * (t + j * z) + (n - i) * (t + j * z) * (i - j) * y(后n-i个红塔造成的伤害加上前i-j个绿塔在后n-i个格子造成的伤害),所以最终的ans=max(ans, damage).

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 1505;
typedef __int64 LL;
LL dp[N][N];
int main()
{
    LL x, y, z, t, n, i, j;
    int T, cas = 0;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%I64d%I64d%I64d%I64d%I64d",&n,&x,&y,&z,&t);
        memset(dp, 0, sizeof(dp));
        LL ans = n * t * x; //全部放红塔
        for(i = 1; i <= n; i++)  //前i个单位长度
        {
            for(j = 0; j <= i; j++) // 蓝塔数量
            {
                if(j == 0)
                    dp[i][j] = dp[i-1][j] + (i - j - 1) * y * t;
                else
                {
                    LL tmp1 = dp[i-1][j-1] + (i - j) * y * (t + (j - 1) * z); //第j个单位长度放蓝塔
                    LL tmp2 = dp[i-1][j] + (i - j - 1) * y * (t + j * z); //第j个单位长度不放蓝塔
                    dp[i][j] = max(tmp1, tmp2);
                }
                ans = max(ans, dp[i][j] + (n - i) * x * (t + j * z) + (n - i) * (t + j * z) * (i - j) * y);
            }
        }
        printf("Case #%d: %I64d\n", ++cas, ans);
    }
    return 0;
}

hdu 4939 Stupid Tower Defense(DP)2014多校训练第7场

时间: 2024-11-05 22:35:09

hdu 4939 Stupid Tower Defense(DP)2014多校训练第7场的相关文章

hdu 4939 Stupid Tower Defense ( dp )

题目链接 题意:给出一条长为n个单位长度的直线,每通过一个单位长度需要t秒. 有3种塔,红塔可以在当前格子每秒造成x点伤害,绿塔可以在之后的格子每秒造成y点伤害, 蓝塔可以使通过单位长度的时间增加z秒.问如何安排3种塔的顺序使得造成的伤害最大,输出最大伤害值. 分析:比赛的时候实在是没有想出来有三种不同的 塔,每种塔的作用不同,怎么dp.看题解才知道,应该把 所有的红塔放到最后面,因为直线的长度是一定的,而红塔在前面不会增加后面的伤害,然后问题就是如何安排 绿塔和蓝塔,我这里d[i][j]代表前

HDU 4939 Stupid Tower Defense(dp+贪心)

dp[i][j]表示到了第i步放了j个减速,造成的伤害.我们用贪心的策略把造成一段伤害的放在最后面,造成持续伤害的与减速放在前i个中这样得到的伤害是最高的. 所以前(i,j)中的伤害为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); 每次造成的伤害就为:dp[i][j]+(n-i)*(j*z+t)*(x+(i-j)*y).然后取一个最大值,就是伤害的最大值了. Stu

2014多校第七场1005 || HDU 4939 Stupid Tower Defense (DP)

题目链接 题意 :长度n单位,从头走到尾,经过每个单位长度需要花费t秒,有三种塔: 红塔 :经过该塔所在单位时,每秒会受到x点伤害. 绿塔 : 经过该塔所在单位之后的每个单位长度时每秒都会经受y点伤害. 蓝塔 : 经过该塔所在单位之后,再走每个单位长度的时候时间会变成t+z. 思路 : 官方题解 : 1 #include <cstdio> 2 #include <cstring> 3 #include <iostream> 4 #define LL long long

dp --- hdu 4939 : Stupid Tower Defense

Stupid Tower Defense Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 1219    Accepted Submission(s): 361 Problem Description FSF is addicted to a stupid tower defense game. The goal of tower

HDU 4939 Stupid Tower Defense(贪心+dp)

HDU Stupid Tower Defense 题目链接 题意:有一些塔,红塔能攻击经过他的,绿塔能攻击经过之后的,蓝塔能把经过之后的减速,求在1-n上放塔,求伤害最大值 思路:一开始以为直接贪心,绿塔最前,蓝塔中间,红塔最后就可以了,结果其实是错的 不过,红塔放最后是肯定的,这个很显然就不多证明了,是贪心的思想 然后就dp[i][j]表示放到i,前面有j个绿塔去状态转移即可 代码: #include <cstdio> #include <cstring> #include &l

HDU 4939 Stupid Tower Defense(dp)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4939 解题报告:一条长度为n的线路,路上的每个单元格可以部署三种塔来给走在这条路上的敌人造成伤害,第一种塔只给在这个塔的范围内的敌人每秒造成x点的伤害,第二种塔给已经经过过这个塔的敌人每秒造成y点伤害,第三种塔能使已经经过了这个塔的敌人的前进的速度减慢,具体效果是,原来敌人经过一个单元格的时间是t秒,经过减速后,经过每个单元格的时间是t + z,这个一个塔减速的效果,减速的效果可以叠加,同样,第二种

hdu 4939 Stupid Tower Defense (dp)

题目大意: 简单的塔防游戏,有三种塔. 一种是减速塔,只能减速它身后的敌人,使之移动速度减慢.通过一格的时间变成加z秒. 两种攻击塔,一种只能打面前,另外一种可以打身后. 思路分析: 我们默认把只能攻击面前的塔放到最后面. 状态方程: dp [i] [j]  表示放到第 i 个位置放了 j 个防御塔能达到的最大伤害. 转移方程:dp [i] [j] =max ( dp[i-1][j] + buildy ,  dp[i-1][j-1] + buildz ) buildy 表示第 i 位置建一个 攻

hdu 4960 Another OCD Patient(dp)2014多校训练第9场

Another OCD Patient                                                                         Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Problem Description Xiaoji is an OCD (obsessive-compulsive disorder) pat

hdu 4901 The Romantic Hero(计数dp)2014多校训练第4场1005

The Romantic Hero                                                                               Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Problem Description There is an old country and the king fell in lov