dp --- hdu 4939 : Stupid Tower Defense

来源:互联网 发布:用java编写游戏 编辑:程序博客网 时间:2024/06/07 03:06
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 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
12 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
 

 

Mean: 

经典的塔防类游戏。

敌人要通过一条过道,你有三种塔:红塔---敌人经过该塔时每秒受到x点伤害;  绿塔---敌人经过该塔后,每秒受到y点伤害; 蓝塔---敌人经过该塔后,经过每座塔的时间变慢z秒。现在要你安排这三种塔,使得对敌人的伤害最大。

 

 

analyse:

 

分析可知,红塔要放到后面。
然后我们枚举红塔的数量i,对前n-i座塔进行dp。
dp[i][j]----表示前i座塔中,放j座蓝塔和i-j座绿塔所造成的最大伤害。
x y z t
状态转移方程:
dp[i][j]=max(dp[i-1][j-1]+y*(i-j)*(t+(j-1)*z),dp[i-1][j]+(i-1-j)*y*(t+j*z))

 

Time complexity:O(n^2)

 

Source code:

 

//Memory   Time// 18424K   1796MS// by : Snarl_jsb#include<algorithm>#include<cstdio>#include<cstring>#include<cstdlib>#include<iostream>#include<vector>#include<queue>#include<stack>#include<string>#include<climits>#include<cmath>#define MAX 1520#define LL long longusing namespace std;LL dp[MAX][MAX];int main(){    LL T,kase=1;    cin>>T;    while(T--)    {        LL n,x,y,z,t,damage;        scanf("%I64d %I64d %I64d %I64d %I64d",&n,&x,&y,&z,&t);        printf("Case #%I64d: ",kase++);        memset(dp,0,sizeof(dp));        dp[1][1]=x;        LL ans=n*x*t;                  //全部放红塔的伤害值        for(LL i=1;i<=n;i++)          //枚举前i个单位长度        {            for(LL j=0;j<=i;j++)     // 枚举前i个单位中蓝塔的数量j            {                if(j==0)                    dp[i][j]=dp[i-1][j]+y*(i-1)*t;                else                {                    LL tmp1=dp[i-1][j-1]+y*(i-j)*(t+z*(j-1));  // 第j座放蓝塔                    LL tmp2=dp[i-1][j]+y*(i-1-j)*(t+z*j);       // 第j座放绿塔                    dp[i][j]=max(tmp1,tmp2);                }                damage=dp[i][j]+(n-i)*x*(t+z*j)+(n-i)*(i-j)*y*(t+z*j);                ans=max(ans,damage);            }        }        cout<<ans<<endl;    }    return 0;}

  

0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 在京东买东西只收到空盒子怎么办 魅族移动数据是灰色的怎么办? 魅族手机账号密码忘记了怎么办视频 淘宝购物退货把单号写错了怎么办 天猫想退货商家不给退货地址怎么办 天天爱消除四星宠物等级已满怎么办 店不干了店里面的财神怎么办 微信显示登陆注册语言打不开怎么办 三星手机解锁以后突然不量怎么办 耐克、阿迪品牌鉴定买到假货怎么办 小米4c盒子不支持有线连接怎么办 一个手机号绑着两个小米账号怎么办 小米5s手机听筒声音小怎么办 淘宝上买手机买到翻新怎么办 小米6用久了很卡怎么办 淘宝商家发错误的退货地址怎么办 买苹果手机时查到了翻新机该怎么办 荣耀9青春版玩王者卡怎么办 红米4x手机声音突然成破音怎么办 红米pro玩王者荣耀卡怎么办 红米手机恢复出厂设置出错了怎么办 红米恢复出厂设置出错了怎么办 应聘工作上当收押金了该怎么办 红米1s密码忘了怎么办 红米1s刷机后开不了机怎么办 红米2a耗电超快怎么办 红米2a手机耗电快怎么办 红米4x触屏失灵怎么办 苹果恢复出厂设置后密码忘记怎么办 红米1s忘记密码锁屏了怎么办 红米3手机忘记解锁图案怎么办 小米5x手机录屏失败怎么办 红米4x手机wif信号不好怎么办 红米4x屏幕换了截屏不好使怎么办 红米手机2a卡慢怎么办? 红米手机连接无线网信号不好怎么办 小米4用久了很卡怎么办 红米4a关不了机怎么办 红米手机屏幕锁了忘记密码怎么办 手机锁了忘记密码怎么办 红米 红米4a开不开机怎么办