God of War
Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1024 Accepted Submission(s): 377
Problem Description
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.
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).
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.
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.
分析:状态压缩dp,状态数为2^20,每位二进制位对应某个英雄
dp[i]:表示在状态i下最大血量
#include<cstdio>
#include<queue>
using namespace std;
const int N=20;
const int S=1<<N;
int dp[S];
int exp[S];//状态S的累计经验值
int A[N],D[N],H[N],E[N];//某个英雄的属性(攻击力、防御力、血量、打败他获得的经验值)
int tol;//状态总数
bool inQ[S];//标记状态S是否在队列里
queue<int> Q;
int max(int a,int b){return a>b?a:b;}
int main(){
int ZA,ZD,ZH,IA,ID,IH,i,j,u,v,n;
char s[N];
while(~scanf("%d%d%d%d%d%d",&ZA,&ZD,&ZH,&IA,&ID,&IH)){
scanf("%d",&n),tol=1<<n;
for(i=0;i<n;i++)scanf("%s%d%d%d%d",s,A+i,D+i,H+i,E+i);
for(i=0;i<tol;i++)dp[i]=-1;
dp[0]=ZH,exp[0]=0;Q.push(0);inQ[0]=1;
while(!Q.empty()){
u=Q.front();Q.pop();inQ[u]=0;
for(i=0;i<n;i++){
v=u|(1<<i);
if(u==v)continue;//该英雄被打过
int lu=exp[u]/100,nA=ZA+IA*lu,nD=ZD+ID*lu,ztg=max(1,nA-D[i]),gtz=max(1,A[i]-nD);
//打之前等级、攻击力、防御力、吕布对英雄的单位伤害、英雄对吕布的单位伤害
int zt=H[i]/ztg+((H[i]%ztg)>0),gt=dp[u]/gtz+((dp[u]%gtz)>0);//获胜所需时间、失败所需时间
if(zt>gt)continue;//失败
exp[v]=exp[u]+E[i];
int lv=exp[v]/100;//当前v状态下等级
dp[v]=max(dp[v],dp[u]-(zt-1)*gtz+IH*(lv-lu));//转移方程
if(!inQ[v])Q.push(v),inQ[v]=1;
}
}
if(dp[tol-1]==-1)puts("Poor LvBu,his period was gone.");
else printf("%d\n",dp[tol-1]);
}
return 0;
}