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. 【windows7】解决IIS 80端口占用问题(亲测)

    1.默认你win机器已经安装并启用了80端口 2.现在你要安装并启用apache服务器 3.首先进行80端口占用检测:netstat -aon|findstr 80 4.找到进程号为404的服务名称, ...

  2. sqlconnection 调用webservice服务

    package cn.itcast.service.urlconnection; import java.io.InputStream; import java.io.OutputStream; im ...

  3. 对象的序列化存储:Serializable 和 Parceable

    在进行Android开发的时候我们有时候需要用到数据的持久化存储,或者在进程之间传递数据.其中就可能需要用到对象的序列化,经过序列化的对象之后可以通过Intent或者Boundle来传输了.接下来还是 ...

  4. JSON对象和JSON字符串以及JSON.parse 函数的使用

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  5. SIM800L透传模式配置

    UART1_SendString("AT+CIPCLOSE=1"); //关闭连接 delay_ms(100); Second_AT_Command("AT+CIPSHU ...

  6. IntelliJ IDEA 学习(一):IntelliJ IDEA15 破解方法(已验证)

    新的破解方法: 1.进到文件夹中:C:\Windows\System32\drivers\etc ,找到hosts文件,用记事本编辑 2.如果没有找到hosts文件,可在查看设置中勾选“显示隐藏的项目 ...

  7. jenkins 下载插件失败处理办法

    jenkins 下载插件失败,提示: java.io.IOException: Downloaded file /app/jenkins_home/plugins/jacoco.jpi.tmp doe ...

  8. vim插件管理利器

    一.pathogen简介 通常情况下安装vim插件,通常是将所有的插件和相关的doc文件都安装在中一文件夹中,如将插件全部安装在/usr/share/vim/vim73/plugin/目录下,将帮助文 ...

  9. Eclipse发布安卓APK包无图标的解决方法

    算是一个Bug,清空项目都不行. 解决方法是卸载掉项目,重新导入.

  10. MySql图解给表添加外键

    关于外键约束的几种方式,请移步鄙人的另外一个博客中的博文  http://blog.csdn.net/hadues/article/details/52558184