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. Nutch相关框架安装使用最佳指南(转帖)

    Nutch相关框架安装使用最佳指南 Chinese installing and using instruction  -  The best guidance in installing and u ...

  2. 你所不知道的 CSS 阴影技巧与细节 滚动视差?CSS 不在话下 神奇的选择器 :focus-within 当角色转换为面试官之后 NPOI 教程 - 3.2 打印相关设置 前端XSS相关整理 委托入门案例

    你所不知道的 CSS 阴影技巧与细节   关于 CSS 阴影,之前已经有写过一篇,box-shadow 与 filter:drop-shadow 详解及奇技淫巧,介绍了一些关于 box-shadow  ...

  3. hdu5293 Tree chain problem 树形dp+线段树

    题目:pid=5293">http://acm.hdu.edu.cn/showproblem.php?pid=5293 在一棵树中,给出若干条链和链的权值.求选取不相交的链使得权值和最 ...

  4. EM 算法 实例

    #coding:utf-8 import math import copy import numpy as np import matplotlib.pyplot as plt isdebug = T ...

  5. ORID方法在敏捷中的利用

    Objective: 上个迭代有哪些让你印象深刻的事情发生?你看到了什么? Reflective:哪些场景让你兴奋?哪些地方不那么顺利? Interpretive:为什么会不顺利?这些数据使你意识到了 ...

  6. Sql UNION 合并多个结果集并排序

    1.建表语句及测试数据: --创建表A CREATE TABLE A( A1 int NULL, A2 nvArchAr(50) NULL, A3 decimAl(18, 0) NULL ) --测试 ...

  7. Go语言核心之美 4.3-多返回值

    在Go语言中.函数能够有多个返回值,这个特性我们已经在之前的样例见过非常多,非常多标准库函数都会返回两个值,一个是期望得到的函数执行结果,另外一个是函数出错时的错误值. 以下的程序是findlinks ...

  8. 批处理-IF详解

    在CMD使用IF /?打开IF的系统帮助(自己看我就不全部列出来了),我们会发现IF有3种基本的用法! IF [NOT] ERRORLEVEL number command IF [NOT] stri ...

  9. js 控制不同客户端 访问不同CSS js

    function loadCSS(flag) { var t='.css'; if((navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios ...

  10. Redis学习笔记——数据类型及操作

    数据操作 redis是key-value的数据,所以每个数据都是一个键值对 键的类型是字符串 值的类型分为五种: 字符串string 哈希hash 列表list 集合set 有序集合zset 数据操作 ...