God of War HDU - 2809

不需要记录最后一个人。
题意:给出战神吕布的初始攻击力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);
	}
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值