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
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.
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)
2 4 3 2 1
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.
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 long
using 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;
}
dp --- hdu 4939 : Stupid Tower Defense的更多相关文章
- HDU 4939 Stupid Tower Defense(dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4939 解题报告:一条长度为n的线路,路上的每个单元格可以部署三种塔来给走在这条路上的敌人造成伤害,第一 ...
- 2014多校第七场1005 || HDU 4939 Stupid Tower Defense (DP)
题目链接 题意 :长度n单位,从头走到尾,经过每个单位长度需要花费t秒,有三种塔: 红塔 :经过该塔所在单位时,每秒会受到x点伤害. 绿塔 : 经过该塔所在单位之后的每个单位长度时每秒都会经受y点伤害 ...
- hdu 4939 Stupid Tower Defense ( dp )
题目链接 题意:给出一条长为n个单位长度的直线,每通过一个单位长度需要t秒. 有3种塔,红塔可以在当前格子每秒造成x点伤害,绿塔可以在之后的格子每秒造成y点伤害, 蓝塔可以使通过单位长度的时间增加z秒 ...
- HDU 4939 Stupid Tower Defense 简单DP
题意: 地图为长为n个单位长度的直线,每通过一个单位长度需要t秒. 有3种塔,红塔可以在当前格子每秒造成x点伤害,绿塔可以在之后格子造成y点伤害,蓝塔可以使通过单位长度的时间增加z秒. 让你安排塔的排 ...
- HDU 4939 Stupid Tower Defense (2014 Multi-University Training Contest 7)
思路:首先红色肯定要放在最后面.前面蓝色和绿色dp求解. dp[i][j] 表示前面(i+j) 个 有 i 个蓝色塔 j个绿色塔 能造成最大伤害. //====================== ...
- HDU 4939 Stupid Tower Defense
dp:枚举red,dp前i 个塔中有j 个蓝塔的最大伤害. 机智的地方:dp前i 个塔的时候可以同时处理n-i 个红塔,这样就少了个循环...(枚举红塔的循环) #include <iostre ...
- HDU 4779:Tower Defense
Tower Defense Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 132768/132768 K (Java/Others)T ...
- hdu4939 Stupid Tower Defense (DP)
2014多校7 第二水的题 4939 Stupid Tower Defense Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 131 ...
- HDU4939Stupid Tower Defense (有思想的dp)
Stupid Tower Defense Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Oth ...
随机推荐
- node访问iis使用keep-alive设置不当
iis默认的连接超时时间为2分钟 ,因此node程序使用keep-alive访问时,keep-alive的时间不应该超过2分钟,否则在请求完成后,node端继续保持连接,2分钟后iis断开连接,会导致 ...
- wamp虚拟主机配置
1.首先打开apache的配置文件httpd.conf,并去掉#Include conf/extra/httpd-vhosts.conf前面的#,启用虚拟主机功能 2.先把localhost配置好,免 ...
- 实战使用Axure设计App,使用WebStorm开发(5) – 实现页面功能
系列文章 实战使用Axure设计App,使用WebStorm开发(1) – 用Axure描述需求 实战使用Axure设计App,使用WebStorm开发(2) – 创建 Ionic 项目 实战使 ...
- CGLib与JDKProxy的区别
Spring AOP 的实现主要有两种:CGLib与JDK自带的Proxy. 他们主要的区别是,需要JDKProxy修改的类必须实现接口(因此也只能代理public方法),在创建Proxy时可以使用c ...
- Atitit.加密算法ati Aes的框架设计v2.2
Atitit.加密算法ati Aes的框架设计v2.2 版本进化1 V2.2 add def decode key api1 v1版本1 Aes的历史2 Atitit.加密算法 des aes ...
- fir.im Weekly - iOS/Android 应用程序架构解析
假如问你一个iOS or Android app的架构,你会从哪些方面来说呢? 本期 fir.im Weekly 收集了关于 iOS/Android 开发资源,也加入了一些关于 Web 前端方面的分 ...
- iOS-网络爬虫
1.iOS开发——网络实用技术OC篇&网络爬虫-使用青花瓷抓取网络数据 2.iOS开发——网络使用技术OC篇&网络爬虫-使用正则表达式抓取网络数据 3.iOS—网络实用技术OC篇&am ...
- iOS----单例模式(Singleton)
单例的意思就是只有一个实例.单例模式确保某一个类只有一个实例,而且自行实例化并向整个系统提供这个实例.这个类称为单例类. 1.单例模式的要点: 显然单例模式的要点有三个:一是某个类只能有一个实例:二是 ...
- jQuery_04之第三方、自定义
1.第三方插件: ①日期:layDate:不依赖于jquery 使用:html:<input class="laydate-icon"> css:引入laydat ...
- Python装饰器详解
python中的装饰器是一个用得非常多的东西,我们可以把一些特定的方法.通用的方法写成一个个装饰器,这就为调用这些方法提供一个非常大的便利,如此提高我们代码的可读性以及简洁性,以及可扩展性. 在学习p ...