hdu 3008 Warcraft,第一道dp题。。。

Warcraft

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


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!
 我看别人说这是入门dp题,然后想着期望dp题挺多的,就想写一写,然后。。
发现,根本写不了。。。
首先是设dp设错啊。。。
好吧,先说下我对dp的理解吧(个人观点)dp就好像数学里面的设未知数,也就是术语的状态然后状态转移方程呢就好像未知数的方程不过状态转移方程是梯推式
这题呢就是设dp[j]=mana 也就是表示boss剩下j点血量是你能剩下的最大mana;当然每次放技能的时候还有判断现在的mana是不是大于等于技能所需mana;
然后因为boss血量和攻击一定,所以可以算出总共能进行多少次回合;如果大于这个回合还没有把boss血量降为0;那么就输出My God;
所以呀,这题就写个3重循环最外层的是回合数;次外层是boss初始血量100;然后内层是技能数;如果当前技能所造成的伤害大于就输出当前回合数;
状态转移方程是dp[j-b[k]]=max(dp[j-b[k]],dp[j]-a[k]+t);
好吧,刚刚突然顿悟,还是把dp叫状态比叫成未知数更确切;
因为每次循环一次回合,dp记录了能把boss降到的所有血量的最大魔法值;
第一次写这么多呀。2333
还有判断mana不能大于最大mana100;
一发ac的。。。
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int n,t,p;
const int Size=105;
int a[Size],b[Size];
bool flag;
int dp[Size];
int main()
{
    while(cin>>n>>t>>p&&n&&t&&p)
    {
        flag=false;
        memset(dp,0,sizeof(dp));
        dp[100]=100;
        for(int i=1;i<=n;i++)
            scanf("%d%d",&a[i],&b[i]);
            a[0]=0,b[0]=1;
            int time=100%p?100/p+1:100/p;
        for(int i=1;i<=time;i++)
            {
                for(int j=1;j<=100;j++)
        {
            if(!dp[j])
            continue;
            for(int k=0;k<=n;k++)
            {
                if(j<=b[k]&&dp[j]>=a[k])
                    {
                    printf("%d\n",i);
                    flag=true;
                    break;
                    }
                if(dp[j]>=a[k])
                dp[j-b[k]]=max(dp[j-b[k]],dp[j]-a[k]+t);
                if(dp[j-b[k]]>100)
                    dp[j-b[k]]=100;
            }
            if(flag)
                break;
        }
        if(flag)
            break;
            }
            if(!flag)
                printf("My god\n");
    }
            return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
代码下载:完整代码,可直接运行 ;运行版本:2022a或2019b或2014a;若运行有问,可私信博主; **仿真咨询 1 各类智能优化算法改进及应用** 生产调度、经济调度、装配线调度、充电优化、车间调度、发车优化、水库调度、三维装箱、物流选址、货位优化、公交排班优化、充电桩布局优化、车间布局优化、集装箱船配载优化、水泵组合优化、解医疗资源分配优化、设施布局优化、可视域基站和无人机选址优化 **2 机器学习和深度学习方面** 卷积神经网络(CNN)、LSTM、支持向量机(SVM)、最小二乘支持向量机(LSSVM)、极限学习机(ELM)、核极限学习机(KELM)、BP、RBF、宽度学习、DBN、RF、RBF、DELM、XGBOOST、TCN实现风电预测、光伏预测、电池寿命预测、辐射源识别、交通流预测、负荷预测、股价预测、PM2.5浓度预测、电池健康状态预测、水体光学参数反演、NLOS信号识别、地铁停车精准预测、变压器故障诊断 **3 图像处理方面** 图像识别、图像分割、图像检测、图像隐藏、图像配准、图像拼接、图像融合、图像增强、图像压缩感知 **4 路径规划方面** 旅行商问(TSP)、车辆路径问(VRP、MVRP、CVRP、VRPTW等)、无人机三维路径规划、无人机协同、无人机编队、机器人路径规划、栅格地图路径规划、多式联运运输问、车辆协同无人机路径规划、天线线性阵列分布优化、车间布局优化 **5 无人机应用方面** 无人机路径规划、无人机控制、无人机编队、无人机协同、无人机任务分配 **6 无线传感器定位及布局方面** 传感器部署优化、通信协议优化、路由优化、目标定位优化、Dv-Hop定位优化、Leach协议优化、WSN覆盖优化、组播优化、RSSI定位优化 **7 信号处理方面** 信号识别、信号加密、信号去噪、信号增强、雷达信号处理、信号水印嵌入提取、肌电信号、脑电信号、信号配时优化 **8 电力系统方面** 微电网优化、无功优化、配电网重构、储能配置 **9 元胞自动机方面** 交通流 人群疏散 病毒扩散 晶体生长 **10 雷达方面** 卡尔曼滤波跟踪、航迹关联、航迹融合

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值