HDOJ题目4939 Stupid Tower Defense(dp)

Stupid Tower Defense

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

Total Submission(s): 1759    Accepted Submission(s): 498

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.

Author

UESTC

Source

2014 Multi-University Training Contest 7

Recommend

We have carefully selected several similar problems for you:  5245 5244 5243 5242 5241

看人家的http://blog.csdn.net/LYHVOYAGE/article/details/38531575

ac代码

#include<stdio.h>
#include<string.h>
#define max(a,b) (a>b?a:b)
__int64 dp[1510][1510];
__int64 n,x,y,z,t;
int main()
{
	int cas,cot=0;
	scanf("%d",&cas);
	while(cas--)
	{
		scanf("%I64d%I64d%I64d%I64d%I64d",&n,&x,&y,&z,&t);
		memset(dp,0,sizeof(dp));
		__int64 ans=n*t*x;
		int i,j;
		for(i=1;i<=n;i++)
		{
			for(j=0;j<=i;j++)
			{
				if(j==0)
					dp[i][j]=dp[i-1][j]+(i-1-j)*y*t;
				else
				{
					__int64 temp1,temp2;
					temp1=dp[i-1][j-1]+(i-j)*y*(t+(j-1)*z);
					temp2=dp[i-1][j]+(i-j-1)*y*(t+j*z);
					dp[i][j]=max(temp1,temp2);
				}
				ans=max(ans,dp[i][j]+(n-i)*x*(t+j*z)+(n-i)*y*(i-j)*(t+j*z));
			}
		}
		printf("Case #%d: %I64d\n",++cot,ans);
	}
}
时间: 2024-08-01 14:31:51

HDOJ题目4939 Stupid Tower Defense(dp)的相关文章

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

HDOJ 4939 Stupid Tower Defense

red放到后面显然更优,dp[i][j]表示前i个塔里有j个blue,最后枚举有多少个red Stupid Tower Defense Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 599    Accepted Submission(s): 163 Problem Description FSF is addicted to

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

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 位置建一个 攻

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)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. Th