hdu 3008:Warcraft(动态规划 背包)
Warcraft
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 957 Accepted Submission(s): 487
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!
10 5
20 10
30 28
76 70
4 2 25
10 5
20 10
30 28
77 70
0 0 0
My god
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!
#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(动态规划 背包)的更多相关文章
- HDU 3008 Warcraft(DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3008 题目大意:人有100血和100魔法,每秒增加 t 魔法(不能超过100).n个技能,每个技能消耗 ...
- HDU 3008 Warcraft
题意:一个人有100点血和100点魔法,Boss有100点血.人有n个技能.每一个技能对Boss有a[i]点伤害, 且会消耗b[i] 的点魔量,人每秒会有t秒魔法恢复(最大为100)Boss每秒有q点 ...
- hdu 2546 典型01背包
分析:每种菜仅仅可以购买一次,但是低于5元不可消费,求剩余金额的最小值问题..其实也就是最接近5元(>=5)时, 购买还没有买过的蔡中最大值问题,当然还有一些临界情况 1.当余额充足时,可以随意 ...
- HDU 3127 WHUgirls(完全背包)
HDU 3127 WHUgirls(完全背包) http://acm.hdu.edu.cn/showproblem.php? pid=3127 题意: 如今有一块X*Y的矩形布条, 然后有n种规格的x ...
- [HDU 3535] AreYouBusy (动态规划 混合背包 值得做很多遍)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3535 题意:有n个任务集合,需要在T个时间单位内完成.每个任务集合有属性,属性为0的代表至少要完成1个 ...
- HDU 1284 钱币兑换问题 (动态规划 背包方案数)
钱币兑换问题 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- HDU 3535 分组混合背包
http://acm.hdu.edu.cn/showproblem.php?pid=3535 题意:有n组工作,T时间,每个工作组中有m个工作,改组分类是s,s是0是组内至少要做一件,是1时最多做一件 ...
- HDU 4003 (树形DP+背包)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4003 题目大意:有K个机器人,走完树上的全部路径,每条路径有个消费.对于一个点,机器人可以出去再回来 ...
- HDU 1561 (树形DP+背包)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1561 题目大意:从树根开始取点.最多取m个点,问最大价值. 解题思路: cost=1的树形背包. 有 ...
随机推荐
- UNIX环境编程初步认识——编程环境搭建
前言 前期学习了Linux的一些基本知识后,在借助前期的学习的基础上想再初步认识一下操作系统的一些环境编程体系相关知识,当中环境的配置和搭建费了非常大的劲,须要一点点摸索和尝试,下边是环境搭建的 ...
- Ubuntu 12.04 LTS 下配置 apache支持SPDY, 使用wireshark 抓包分析SPDY 协议
1.安装apache sudo apt-get install apache2 root@ubuntu:/etc/apache2/mods-enabled# apache2 -v Server ver ...
- DBCP(一)数据源配置文件
DBCP是Apache开发的数据源API,使用的话需要导入dbcp jar包.collections jar包.pool jar包. 其数据源匹配的配置文件格式如下: #连接设置 driverCl ...
- C#:将空间数据加载到树视图控件
自己 整理了 下 代码 测试了下 还行... #region 操作树视图控件 /// <summary> /// 自定义需要的类型 /// </summary> enum Da ...
- SQL命令查看Mysql数据库大小
SQL命令查看Mysql数据库大小的方法. 要想知道每个数据库的大小的话,步骤如下:1.进入information_schema 数据库(存放了其他的数据库的信息)use information_sc ...
- Atitit. Gui控件and面板----程序快速启动区--最佳实践Launchy ObjectDock-o0g
Atitit. Gui控件and面板----程序快速启动区--最佳实践Launchy ObjectDock-o0g 两个方式::: 键盘式::先用热键呼叫出QS,然后开始输入程序中的部分字母,按En ...
- 【Android】15.4 例15-2--Notification基本用法
分类:C#.Android.VS2015: 创建日期:2016-02-29 一.简介 上一节介绍了通知(Notification)相关的基本内容.这一节先用一个简单示例演示创建和发布本地通知的基本用法 ...
- 用JIRA管理你的项目
https://blog.csdn.net/gaowenhui2008/article/details/70241657 (一) JIRA环境搭建
- filebeat+kafka失败
filebeat端配置 #----------------------------- Kafka output -------------------------------- output.kafk ...
- 解决:Access denied for user 'root'@'localhost' (using password: YES)
症状: 重新安装了MySQL,改变了root的密码,因此,在java代码中修改了某个DatabaseConnectionImpl的DBPASSWORD 在java中写了一些代码测试MySQL的插入和查 ...