不需要记录最后一个人。
题意:给出战神吕布的初始攻击力ATI、防御力DEF、生命值HP、每升一级增加的攻击力In_ATI,增加的防御力In_DEF和增加的生命值In_HP。然后给出n个敌人的攻击力、防御力、生命值和杀死该单位能获得的经验值EXP。 吕布的初始经验值EXP是0,初始等级level是1,每当EXP>=level*100时就会升级。
在吕布LvBu和敌人A之间的战斗有3条规则
1.吕布攻击A,A失去 Max(1,LvBu’s ATI- A’s DEF) HP;
2.A攻击吕布,吕布失去Max(1,A’ATI- LvBu’DEF)HP;
3.战斗持续到任意一方死亡
如果吕布能够将全部敌人杀死,并且自己不死,那么输出能够余下的最大HP,否则输出"Poor LvBu,his period was gone."
思路:属于状态压缩的题目,用i表示敌方的状态,dp[i]来表示杀死状态i后的最大血量
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
struct hero{
int a,d,h,l;
int e;
}dp[(1<<20)+1];
struct node{
int a,d,h,e;
}en[25];
int main()
{
int a2,d2,h2,n;char name[25];
while(scanf("%d%d%d%d%d%d",&dp[0].a,&dp[0].d,&dp[0].h,&a2,&d2,&h2)!=EOF)
{
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%s%d%d%d%d",name,&en[i].a,&en[i].d,&en[i].h,&en[i].e);
}
for(int i=1;i<(1<<20);i++)
dp[i].h=0;
dp[0].l=1;
dp[0].e=0;
for(int j=0;j<=(1<<n)-1;j++)
{
if(dp[j].h<=0) continue;
for(int k=0;k<n;k++)
{
hero temp=dp[j];
if((j&(1<<k))) continue;
int sub=max(temp.a-en[k].d,1);
int sub1=max(en[k].a-temp.d,1);
int time=(en[k].h/sub);
if(en[k].h%sub==0) time--;
temp.h-=time*sub1;
if(temp.h<=0) continue;
temp.e+=en[k].e;
if(temp.e>=temp.l*100)
{
temp.l++;
temp.a+=a2;
temp.d+=d2;
temp.h+=h2;
}
if(temp.h>dp[j|(1<<k)].h) dp[j|(1<<k)]=temp;
}
}
if(dp[(1<<n)-1].h<=0)
printf("Poor LvBu,his period was gone.\n");
else printf("%d\n",dp[(1<<n)-1].h);
}
}