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;
}


全部评论

相关推荐

程序员小白条:投太少了,多投点吧,二本就海投,然后简历上加点奖项或者四六级之类的,别管有没有用,另外最好搞下个人博客,定期输出一些文章和学习总结,也可以去github参与一下开源项目提一些PR,总会有中小公司看的上的
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务