Warcraft

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 957    Accepted Submission(s): 487

Problem Description
Have you ever played the Warcraft?It doesn't matter whether you have played it !We will give you such an experience.There are so many Heroes in it,but you could only choose one of them.Each Hero has his own skills.When such a Skill is used ,it costs some MagicValue,but hurts the Boss at the same time.Using the skills needs intellegence,one should hurt the enemy to the most when using certain MagicValue.

Now we send you to complete such a duty to kill the Boss(So cool~~).To simplify the problem:you can assume the LifeValue of the monster is 100, your LifeValue is 100,but you have also a 100 MagicValue!You can choose to use the ordinary Attack(which doesn't cost MagicValue),or a certain skill(in condition that you own this skill and the MagicValue you have at that time is no less than the skill costs),there is no free lunch so that you should pay certain MagicValue after you use one skill!But we are good enough to offer you a "ResumingCirclet"(with which you can resume the MagicValue each seconds),But you can't own more than 100 MagicValue and resuming MagicValue is always after you attack.The Boss is cruel , be careful!

 
Input
There are several test cases,intergers n ,t and q (0<n<=100,1<=t<=5,q>0) in the first line which mean you own n kinds of skills ,and the "ResumingCirclet" helps you resume t points of MagicValue per second and q is of course the hurt points of LifeValue the Boss attack you each time(we assume when fighting in a second the attack you show is before the Boss).Then n lines follow,each has 2 intergers ai and bi(0<ai,bi<=100).which means using i skill costs you ai MagicValue and costs the Boss bi LifeValue.The last case is n=t=q=0.
 
Output
Output an interger min (the minimun time you need to kill the Boss)in one line .But if you die(the LifeValue is no more than 0) ,output "My god"!
 
Sample Input
4 2 25
10 5
20 10
30 28
76 70
4 2 25
10 5
20 10
30 28
77 70
0 0 0
 
Sample Output
4
My god

Hint

Hint:
When fighting,you can only choose one kind of skill or just to use the ordinary attack in the whole second,the ordinary attack costs the Boss 1
points of LifeValue,the Boss can only use ordinary attack which costs a whole second at a time.Good Luck To You!

 
Source
 
Recommend
gaojie   |   We have carefully selected several similar problems for you:  1158 1227 1300 1501 1502 

 
  动态规划的背包问题。
  不明白什么是背包问题见链接:百度百科 - 背包问题
  一开始没想到怎么做,看了解题报告才有了思路。链接在这:HDU 3008 背包
  
  dp[i][j]代表第 i 秒剩余 j 魔法值时所作出的伤害。
  思路:循环时间 i ,不断产生第 i 秒的所有子问题(dp[i][0..100]),记录可能的情况的伤害值,其他情况记录为-1。累积所有子问题直到出现符合情况(dp[i][j]>=100)的子问题,退出循环输出结果(一定是最min的)。或是达到限定时间(因为到达这个时间的时候,你已经被BOSS打的没血了)。
  注意剪枝以及一些边界情况,细节没处理好很容易WA。
  
  代码可能不是很简练,但是我觉得还是容易看懂的。
  

 #include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int a[],b[];
int dp[][]; //代表到第 i 秒剩余 j 魔法值打掉BOSS的HP
int main()
{
int n,t,q;
while(cin>>n>>t>>q){
if(n== && t== && q==)
break;
for(int i=;i<=n;i++)
cin>>a[i]>>b[i];
//freopen("output.txt","w",stdout);
memset(dp,-,sizeof(dp));
dp[][]=; //刚开始的时候出了MP=100,其余都为无效
int T;
if(%q==)
T=/q;
else
T=/q+;
int i,j,k;
for(i=;i<=T;i++){ //最多到100秒
for(j=;j<=;j++){ //一次遍历dp[i-1][0..100]的所有情况
if(dp[i-][j]==-)
continue;
for(k=;k<=n;k++){ //使用技能攻击
if(j-a[k]<) //如果剩余的MP不足以使用这个技能,则跳出本次循环
continue;
int temp;
temp=j-a[k]+t>?:j-a[k]+t;
if(dp[i][temp]==-){ //没到达过这个MP
dp[i][temp]=dp[i-][j]+b[k];
if(dp[i][temp]>=)
goto label;
}
else{ //说明之前有降到过这个MP,这个时候比较哪一个伤害高,记录伤害高的值
if(dp[i-][j]+b[k] > dp[i][temp]){ //如果当前技能伤害高
dp[i][temp]=dp[i-][j]+b[k];
if(dp[i][temp]>=)
goto label;
}
}
}
if(j+t>=){ //用普通攻击
if(dp[i-][j]+ > dp[i][]) {
dp[i][] = dp[i-][j]+;
if(dp[i][]>=)
goto label;
}
}
else{
if(dp[i-][j]+ > dp[i][j+t]){
dp[i][j+t]=dp[i-][j]+;
if(dp[i][j+t]>=)
goto label;
}
}
}
}
label:
if(i>T) //正常退出,代表在规定时间内没打死BOSS,你挂了
cout<<"My god"<<endl;
else
cout<<i<<endl;
}
return ;
}

Freecode : www.cnblogs.com/yym2013

hdu 3008:Warcraft(动态规划 背包)的更多相关文章

  1. HDU 3008 Warcraft(DP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3008 题目大意:人有100血和100魔法,每秒增加 t 魔法(不能超过100).n个技能,每个技能消耗 ...

  2. HDU 3008 Warcraft

    题意:一个人有100点血和100点魔法,Boss有100点血.人有n个技能.每一个技能对Boss有a[i]点伤害, 且会消耗b[i] 的点魔量,人每秒会有t秒魔法恢复(最大为100)Boss每秒有q点 ...

  3. hdu 2546 典型01背包

    分析:每种菜仅仅可以购买一次,但是低于5元不可消费,求剩余金额的最小值问题..其实也就是最接近5元(>=5)时, 购买还没有买过的蔡中最大值问题,当然还有一些临界情况 1.当余额充足时,可以随意 ...

  4. HDU 3127 WHUgirls(完全背包)

    HDU 3127 WHUgirls(完全背包) http://acm.hdu.edu.cn/showproblem.php? pid=3127 题意: 如今有一块X*Y的矩形布条, 然后有n种规格的x ...

  5. [HDU 3535] AreYouBusy (动态规划 混合背包 值得做很多遍)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3535 题意:有n个任务集合,需要在T个时间单位内完成.每个任务集合有属性,属性为0的代表至少要完成1个 ...

  6. HDU 1284 钱币兑换问题 (动态规划 背包方案数)

    钱币兑换问题 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  7. HDU 3535 分组混合背包

    http://acm.hdu.edu.cn/showproblem.php?pid=3535 题意:有n组工作,T时间,每个工作组中有m个工作,改组分类是s,s是0是组内至少要做一件,是1时最多做一件 ...

  8. HDU 4003 (树形DP+背包)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4003 题目大意:有K个机器人,走完树上的全部路径,每条路径有个消费.对于一个点,机器人可以出去再回来 ...

  9. HDU 1561 (树形DP+背包)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1561 题目大意:从树根开始取点.最多取m个点,问最大价值. 解题思路: cost=1的树形背包. 有 ...

随机推荐

  1. Eddy&#39;s digital Roots

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission ...

  2. Java Callable 与 Future

  3. /dev/null 和 /dev/zero

    1.概论 -- 来自维基的解释 /dev/null  : 在类Unix系统中,/dev/null,或称空设备,是一个特殊的设备文件,它丢弃一切写入其中的数据(但报告写入操作成功),读取它则会立即得到一 ...

  4. python环境变量的配置

    每个python程序都须要import非常多包.有些系统包是不用安装的.有些第三方包是须要安装的. 在同一台电脑里的linux环境里,安装了第三方包,基本就适用于了整个系统环境. 这里能够用下面方法, ...

  5. c#:无法将类型为“System.DBNull”的对象强制转换为类型“System.String”

    解决办法: 使用转换函数即可: Convert.ToString(要转换的值);

  6. T-sql 根据日期时间 按年份、月份、天来统计

    看统计结果: 这里利用的是convert函数,这里不得不说一下convert函数 CONVERT() 函数是把日期转换为新数据类型的通用函数. CONVERT() 函数可以用不同的格式显示日期/时间数 ...

  7. 摘:SQL Server数据类型的25种

    我们大家都知道数据类弄是数据的一种基本属性,其主要是表示数据在实际操作中所表示信息的类型.任何一种计算机语言都定义了自己的数据类型. 当然,不同的程序语言都具有不同的特点,所定义的SQL Server ...

  8. docker 容器自启动

    我们设置了docker自启动后,docker可以管理各种容器了,对于容器我们也可以设置重启的策略. 在容器退出或断电开机后,docker可以通过在容器创建时的--restart参数来指定重启策略: # ...

  9. AutoFac文档10(转载)

    目录 开始 Registering components 控制范围和生命周期 用模块结构化Autofac xml配置 与.net集成 深入理解Autofac 指导 关于 词汇表 循环依赖 循环依赖是指 ...

  10. JEECG与帆软报表集成

    将FineReport 集成到自己的web项目中,生成报表,可以方便快捷的和自己的项目融合在一起.简化了利用poi的导出遇到的问题. 1.首先在FR中建立好一个模板      例如:我的这张模板是连接 ...