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.

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.

状压dp,最多20个敌人,用0 1 表示这个敌人是否杀过,1杀过,0没杀。
dp[i]=在i状态的最大hp。

1
2
for(i=0;i<(1 << N)-1;i++)
for(当前状态再多杀一个)

状态从00000000->11111111

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<string>
#include<algorithm>
using namespace std;
struct enemy
{
string name;
int ati, def, hp,exp;
void read()
{
cin >> name >> ati >> def >> hp >> exp;
}
}e[22];
int dp[1 << 21];
int fight(int ati, int def, int hp, int eati, int edef, int ehp)
{
while (ehp>0)
{
ehp -= max(ati - edef, 1);
if (ehp > 0)
hp -= max(1, eati - def);
}
return max(-1, hp);
}
int main()
{
int ATI, DEF, HP, inati, indef, inhp, exp;
int N;
while (~scanf("%d%d%d%d%d%d%d", &ATI, &DEF, &HP, &inati, &indef, &inhp, &N))
{
memset(dp, 0, sizeof(dp));
int i, j;
for (i = 0; i < N; i++) e[i].read();
dp[0] = HP;
int temp;
for (i = 0; i <= (1 << N) - 1; i++)
{
if (dp[i] <= 0)
continue;
int hp, def, ati, exp;
exp = 0;
for (int I = 0; I < N; I++)
{
if ((1 << I)&i)
{
exp += e[I].exp;
}
}
def = DEF + (exp / 100 * indef);
ati = ATI + (exp / 100 * inati);
hp = dp[i];
for (j = 0; j < N; j++)
{
temp = 1 << j;
if ((temp&i) == 0)
{
temp = temp | i;
int thp = fight(ati, def, hp, e[j].ati, e[j].def, e[j].hp);
if (thp > 0)
{
if ((exp + e[j].exp) / 100 > exp / 100)//level up
thp += inhp;
dp[temp] = max(dp[temp], thp);
}
}
}
}
if (dp[(1 << N) - 1] > 0)
{
cout << dp[(1 << N) - 1]<<endl;
}
else
{
cout << "Poor LvBu,his period was gone.\n";
}
}
}