HDU4939:Stupid Tower Defense(DP)

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

最优情况下,红塔必然都在最后,dp[i][j]代表前i个有j个蓝塔,枚举最后红塔的个数和前面蓝塔的个数进行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(a))
#define w(x) while(x)
#define ll __int64

ll 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;//都是红塔
        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;
}

HDU4939:Stupid Tower Defense(DP)

时间: 2024-10-10 03:32:02

HDU4939:Stupid Tower Defense(DP)的相关文章

hdu4939 Stupid Tower Defense(Dp)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4939 Stupid Tower Defense Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 493    Accepted Submission(s): 129 Problem Description FSF is addicte

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

hdu4939Stupid Tower Defense dp

//给你三个塔 //红塔:敌人过红塔时有每秒x伤害 //绿塔:敌人过绿塔后有每秒y伤害 //蓝塔:敌人过蓝塔后过每一格时间增加z //问敌人过n个格造成最大伤害 //很容易想到红塔必然放最后 //所以对于每一格的选择只有蓝塔和红塔 //用dp[i][j]表示对于前i格选了j个蓝塔 //dp[i][j] = max(dp[i-1][j] + (i-1-j)*y*(t+j*z) , dp[i-1][j-1] + (i-j)*y*(t+(j-1)*z)) ; //然后 ans = max(ans ,

hdu4939Stupid Tower Defense(DP)

题目:hdu4939Stupid Tower Defense(DP) 题目大意:保卫游戏.给出一条长度n的道路,这条道路上每个单元长度可以放一个塔.现在有三种塔:红塔:怪经过这个塔的时候受到X的伤害每秒.绿塔:怪经过这个塔之后,以后的每秒都受到Y的伤害.蓝塔:怪经过这个塔后,之后每经过单元长度的时间加长为t + Z:问怎样选择这三种塔能够使得伤害值最大. 解题思路:一开始没有想到这是DP, 看了题解才发现放塔的时候红塔应该放在最后面最优,那么就只要放蓝绿塔就行,而且前面哪个位置放了蓝绿塔对后面是

hdu4939 Stupid Tower Defense (DP)

2014多校7 第二水的题 4939 Stupid Tower Defense Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 366    Accepted Submission(s): 88 Problem Description FSF is addicted to a stupid tower defense game.

HDU4939Stupid Tower Defense (有思想的dp)

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

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

HDU 4939 Stupid Tower Defense(贪心+dp)

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