一道有意思的DP
Warcraft
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1253 Accepted Submission(s): 657
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!
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 godHintHint: 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
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<climits>
#include<queue>
#include<vector>
#include<map>
#include<sstream>
#include<set>
#include<stack>
#include<utility>
//#pragma comment(linker, "/STACK:102400000,102400000")
#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626
#define eps 1e-10
#define sqr(x) ((x)*(x))
#define FOR0(i,n) for(int i=0 ;i<(n) ;i++)
#define FOR1(i,n) for(int i=1 ;i<=(n) ;i++)
#define FORD(i,n) for(int i=(n) ;i>=0 ;i--)
#define lson num<<1,l,mid
#define rson num<<1|1,mid+1,r
#define MID int mid=(l+r)>>1
#define zero(x)((x>0? x:-x)<1e-15)
using namespace std;
//const int maxn= ;
const int maxspell= 100+5 ;
//const int maxm= ;
//const int INF= ;
//typedef long long ll;
//ifstream fin("input.txt");
//ofstream fout("output.txt");
//fin.close();
//fout.close();
//freopen("a.in","r",stdin);
//freopen("a.out","w",stdout);
int spelllist,recover,bossatk;
int cost[maxspell];
int atk[maxspell];
int dp[100+5][100+5][100+5];
int DP(int health,int magicka,int bosslife)
{
// cout<<"hp,mp,bosslife"<<health<<" "<<magicka<<" "<<bosslife<<endl;
int &ans=dp[health][magicka][bosslife];
if(ans!=-1) return ans;
ans=INF;
magicka= min(100,magicka+recover );
for(int i=1;i<=spelllist+1;i++)
{
if(magicka<cost[i]) continue;
int bosslife2=bosslife-atk[i];
if(bosslife2<=0) { ans=1;break;}
int health2=health-bossatk;
if(health2<=0) continue;
int magicka2=magicka-cost[i] ;
ans=min(ans,1+ DP(health2,magicka2,bosslife2));
}
// cout<<ans<<endl;
return ans;
}
int main()
{
int i,j;
while(~scanf("%d%d%d",&spelllist,&recover,&bossatk)&&(spelllist||recover||bossatk))
{
for(int i=1;i<=spelllist;i++)
scanf("%d%d",&cost[i],&atk[i]);
cost[spelllist+1]=0,atk[spelllist+1]=1;//普通攻击
memset(dp,-1,sizeof dp);
if(DP(100,100,100)<=100)printf("%d\n",DP(100,100,100));
else puts("My god");
}
return 0;
}
/*
2 2 25
76 70
30 28
4 2 25
10 5
20 10
30 28
77 70
0 0 0
*/