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. 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:  4944 4943 4942 4941 4940 

题意:塔防,怪过每个块用的初始时间为t。每块可以建一个塔,有三种塔,一种是红塔,怪经过当前格子时每秒输出x;一种绿塔,怪过了当前格子后每秒被毒y血;一种是蓝塔,怪经过当前格子后经过每格的时间增加z秒。绿塔和蓝塔效果都可叠加,求最高输出。

题解:DP。

思考题面,可以想到红塔放最后是最优解,可以反证得:如果有个红塔后面有个不红的塔,交换它们肯定可以得更优解。

这样我们就枚举不红的塔的数量、绿塔的数量,f[i][j]表示有前面有i个不红的塔,其中绿塔有j个时,蓝绿塔在全路段的输出和。

因为已知i,j时,后面的红塔的输出也是固定的(只随着i,j变化,ij固定时红塔输出不变),所以我们dp求得各种ij的最大的f[i][j],ans每次更新。

由于数好像有点大,用超碉的会滚的队列比较爽。

 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 long
14 #define usll unsigned ll
15 #define mz(array) memset(array, 0, sizeof(array))
16 #define minf(array) memset(array, 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%d",&x,&y)
21 #define RD3(x,y,z) scanf("%d%d%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 blue
29
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%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++) { ///第1到第i个不放红的
44             for(j=0; j<=i; j++) { ///第1个到第i个有j个green
45                 k=i-j;///第1个到第i个有k个blue
46                 if(k>0) {///第i个放蓝的
47                     f[now][j][k]=f[pre][j][k-1] + j*y*z*(n-i);///放这个蓝的接下来n-i格每格增加了z时间
48                 }
49                 if(j>0) {///放绿的
50                     f[now][j][k]=max(f[now][j][k],f[pre][j-1][k] + y*(t+k*z)*(n-i) );///放这个绿的每秒增加y伤害
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 }

hdu4939 Stupid Tower Defense (DP),布布扣,bubuko.com

时间: 2024-12-10 03:18:09

hdu4939 Stupid Tower Defense (DP)的相关文章

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

hdu4939Stupid Tower Defense(DP)

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

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

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

HDU 4939 Stupid Tower Defense(dp)

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

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)

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

hdu 5623 KK&#39;s Number(dp)

问题描述 我们可爱的KK有一个有趣的数学游戏:这个游戏需要两个人,有N\left(1\leq N\leq 5*{10}^{4} \right)N(1≤N≤5∗10?4??)个数,每次KK都会先拿数.每次可以拿任意多个数,直到NN个数被拿完.每次获得的得分为取的数中的最小值,KK和对手的策略都是尽可能使得自己的得分减去对手的得分更大.在这样的情况下,最终KK的得分减去对手的得分会是多少? 输入描述 第一行一个数T\left( 1\leq T\leq 10\right)T(1≤T≤10),表示数据组