God of War(状压dp)

https://cn.vjudge.net/contest/312854#problem/B

At 184~280 A.D ,there were many kingdoms in China. Three strongest among them are "Wei", "Shu", "Wu". People call this period as "Three Kingdoms". 
HH is a super "Three Kingdoms" fan, because at this period there were many heroes and exciting stories. Among the heroes HH worships LvBu most. 
LvBu is the God of War and is also intelligent, but his ambition is too big while enemies are too powerful .Many monarchs wanted to kill him. 
At 198 A.D ,CaoCao fought with LvBu at Xuzhou.Though Lvbu is the God of War ,CaoCao had so many generals: Xuchu,DianWei XiahouChun……Facing so many heroes ,could LvBu beat all of them? 
 
Given the LvBu's ATI, DEF, HP, and enemies’ ATI, DEF,HP, experience (if LvBu killed one of his enemies, he can get that experience ,and if his experience got more than or equal to 100*level,he would level-up and become stronger) and the In_ATI,In_DEF,In_HP(indicating when LvBu levels up,his ability will increase this point). 
Each turn LvBu will choose an enemy to fight. Please help LvBu find a way to beat all of enemies and survive with the max HP. 
Here’s a fight between LvBu and A: 
If LvBu attack A, A will lose Max(1,LvBu's ATI- A's DEF) hp;
If A survived, he will give LvBu Max(1,A'ATI- LvBu'DEF) injury.
If LvBu is still alive, repeat it untill someone is dead(hp <= 0).
 
LvBu's initial level is 1 and experience is 0,and he can level up many times.

Input

The input contains at most 20 test cases. 
For each case , the first line contains six intergers ,indicating LvBu's ATI,DEF,HP and In_ATI,In_DEF,In_HP. 
The next line gives an interger N(0<N<=20),indicating the number of the enemies . 
Then N lines followed, every line contains the name(the length of each name is no more than 20),ATI,DEF,HP, experience(1<experience<=100).

Output

If LvBu is dead output "Poor LvBu,his period was gone." 
Or output the maximum HP left.

Sample Input

100  80  100  5  5  5
2
ZhangFei 95  75  100  100 
XuChu 90  90  100  90

100 75 100 5 5 5
1
GuanYu 95 85 100 100

Sample Output

30
Poor LvBu,his period was gone.

题目大意:吕布大战群雄,每位英雄都有自己的攻击力,防御力,还有hp(血量),吕布比较特殊,当他积累够100的经验值时他可以升级 。。升级的话加属性。

这个比较公平一点,是单挑,每一位英雄轮流与吕布作战,当吕布杀死一个英雄后,可以得到一定的经验值,问吕布能不能杀死所有的英雄,如果可以的话,求出最后能剩余的最大血量

思路:状压dp,把杀死的英雄状态压缩,维护该状态下的最大血量

 

有人认为

因为防御、攻击和血量直接相关,如果血量不是最优的,而攻击和防御远远的高出很多,这样也可能是最优解

 

 
 

 

我的理解是:当前状态已经确定了,也就是说把这几个人杀了,那么得到的经验是唯一确定的,也就是说防御、攻击是完全相同的,只有血量会因为战斗顺序不一样而不同,所以只需要维护该状态下的最大血量就ok

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct node{
	int ATI,DEF,HP,exp,lv;
}dp[1<<20],hero[20],tmp;
char s[25];
int main(){
	ios::sync_with_stdio(false);
    cout.tie(NULL);
    int In_ATI,In_DEF,In_HP;
    while(~scanf("%d%d%d%d%d%d",&dp[0].ATI,&dp[0].DEF,&dp[0].HP,&In_ATI,&In_DEF,&In_HP)){
    	int n;
	    scanf("%d",&n);
		for(int i=0;i<n;i++)
		    scanf("%s%d%d%d%d",s,&hero[i].ATI,&hero[i].DEF,&hero[i].HP,&hero[i].exp);
		int up=1<<n;
		dp[0].lv=1;
		for(int i=1;i<up;i++) dp[i].HP=0,dp[i].exp=0;//初始化 
		for(int i=0;i<up;i++){//枚举状态 
			if(dp[i].HP<=0) continue;
			for(int j=0;j<n;j++){//枚举现在要与谁战斗 
				if(i&(1<<j))  continue;//已经打过了
				int k1=max(dp[i].ATI-hero[j].DEF,1);
				int k2=max(hero[j].ATI-dp[i].DEF,1);
				k1=hero[j].HP/k1+(hero[j].HP%k1==0?0:1);//吕布杀别人需要的攻击次数 
				k2=dp[i].HP/k2+(dp[i].HP%k2==0?0:1);//别人杀吕布需要的攻击次数 
				if(k1>k2) continue;//吕布被杀,肯定不能用来更新最优解 
				tmp=dp[i];
				tmp.HP-=(k1-1)*max(hero[j].ATI-dp[i].DEF,1);
				tmp.exp+=hero[j].exp;
				if(tmp.exp>=tmp.lv*100){
					tmp.lv++;
					tmp.ATI+=In_ATI;
					tmp.DEF+=In_DEF;
					tmp.HP+=In_HP;
				}
				if(tmp.HP>dp[i|(1<<j)].HP)
				dp[i|(1<<j)]=tmp;
			}
		}
		if(dp[up-1].HP==0) printf("Poor LvBu,his period was gone.\n");
		else printf("%d\n",dp[up-1].HP);  
	}
	return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值