#include <cstdio>#include <cstring>#include <algorithm>using namespace std;#define P(p, a, b) ((p * a + (100 - p) * b) / 100.0)#define LP_INIT_HP 999#define LP_LEVEL 50#define LP_GENDER 0#define RECOVER_HP 200#define X_CHOP_ACC 30#define X_CHOP_DAM 300struct LegendaryPokemon { int level, gender, maxhp; int run[5], p[5]; int n, c[4][4]; struct StatusA {char b[5]; int hp: 12; int nhp: 5; }; struct StatusB { int hp: 12;int nhp: 5; int confuse: 8; int status: 2; int sr: 3; int poison: 11; int pr: 3; }; int p1, p2, bb[5]; double gao() { StatusA a; StatusB b; for (int i = 0; i < 5; ++i) { a.b[i] = bb[i]; } a.hp = maxhp; a.nhp = p1; memset(&b, 0, sizeof(StatusB)); b.hp = LP_INIT_HP; b.nhp = p2; p[0] = 5; p[1] = 10; p[2] = 15; p[3] = level > LP_LEVEL ? 18 : p[1]; p[4] = gender != LP_GENDER ? 20 : 0; return gao1(0, a, b); } double gao1(int r, StatusA a, StatusB b) const { if (a.hp <= 0 || b.hp <= 0) { return 0; } if (a.b[0] == 0 && a.b[1] == 0 && a.b[2] == 0 && a.b[3] == 0 && a.b[4] == 0) { return 0; } double ret = 0; double tmp = gao2(r, a, b); for (int i = 0; i < n; ++i) { StatusB b2 = b; int pp = c[i][2]; switch (c[i][0]) { case 1: b2.hp -= c[i][1]; break; case 2: if (b2.sr == 0) { b2.sr = 3; if (c[i][1] == 0) { b2.status = 0; } else { b2.status = 1; b2.confuse = c[i][1]; } } break; case 3: b2.hp -= c[i][1]; if (b2.pr == 0) { b2.pr = 3; b2.poison = c[i][2]; } pp = c[i][3]; break; } ret = max(ret, P(pp, gao2(r, a, b2), tmp)); } for (int i = 0; i < 5; ++i) { if (a.b[i] > 0) { int pp = p[i]; if (b.hp <= 50) {pp += 10; } else if (b.hp <= 100) { pp += 5; } if (b.pr > 0) { pp += 10; } if (b.sr > 0) { pp += 5; } --a.b[i]; ret = max(ret, P(pp, 1, gao2(r, a, b))); ++a.b[i]; } } if (a.nhp > 0) { a.hp = min(maxhp, a.hp + RECOVER_HP); --a.nhp; ret = max(ret, gao2(r, a, b)); } return max(ret, tmp); } double gao2(int r, StatusA a, StatusB b) const { if (a.hp <= 0 || b.hp <= 0) { return 0; } if (run[r] >= 100) { return 0; } if (b.hp <= 150 && b.nhp > 0) { b.hp += RECOVER_HP; --b.nhp; if (b.pr > 0) { --b.pr; if ((b.hp -= b.poison) <= 0) { return 0; } } if (b.sr > 0) { --b.sr; } return (1 - run[r] / 100.0) * gao1(r + 1, a, b); } if (b.pr > 0) { --b.pr; if ((b.hp -= b.poison) <= 0) { return 0; } } if (b.sr > 0) { --b.sr; double tmp = gao1(r + 1, a, b); if (b.status == 0) { return (1 - run[r] / 100.0) * tmp; } else { StatusA a2 = a; a2.hp -= X_CHOP_DAM; StatusB b2 = b; b2.hp -= X_CHOP_DAM; return (1 - run[r] / 100.0) * P(b.confuse, P(X_CHOP_ACC, gao1(r + 1, a, b2), tmp), P(X_CHOP_ACC, gao1(r + 1, a2, b), tmp)); } } else { StatusA a2 = a; a2.hp -= X_CHOP_DAM; return (1 - run[r] / 100.0) * P(X_CHOP_ACC, gao1(r + 1, a2, b), gao1(r + 1, a, b)); } }};int main() { LegendaryPokemon lp; while (scanf("%d%d%d", &lp.level, &lp.gender, &lp.maxhp) != EOF && lp.maxhp > 0) { for (int i = 0; i < 5; ++i) { scanf("%d", &lp.run[i]); } scanf("%d%d", &lp.p1, &lp.p2); for (int i = 0; i < 5; ++i) { scanf("%d", &lp.bb[i]); } scanf("%d", &lp.n); for (int i = 0; i < lp.n; ++i) { scanf("%d%d%d", &lp.c[i][0], &lp.c[i][1], &lp.c[i][2]); if (lp.c[i][0] == 3) { scanf("%d", &lp.c[i][3]); } } printf("%.4lfn", lp.gao()); } return 0;}