/* -*- coding: utf-8 -*- * * 1196.cc: No.1196 A lazy student - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 1000000; /* typedef */ /* global variables */ char s[MAX_N + 4]; double p, q, r; /* subroutines */ double expr(char *(&cpt)); double elm(char *(&cpt)) { if (*cpt == 'Y') { cpt += 3; // 'YES' return 1.0; } if (*cpt == 'N') { cpt += 2; // 'NO' return 0.0; } if (*cpt == '(') { cpt++; // '(' double e0 = expr(cpt); cpt++; // ')' return e0; } cpt += 7; // 'random(' double e0 = expr(cpt); double e1 = expr(cpt); cpt++; // ')' return (e0 * e1) * p + (1.0 - e0 * e1) * q; } double term(char *(&cpt)) { double e0 = elm(cpt); while (*cpt == 'a') { cpt += 3; // 'and' double e1 = elm(cpt); e0 *= e1; e0 = r * e0 + (1.0 - r) * (1.0 - e0); } return e0; } double expr(char *(&cpt)) { double e0 = term(cpt); while (*cpt == 'o') { cpt += 2; // 'or' double e1 = term(cpt); e0 = 1.0 - (1.0 - e0) * (1.0 - e1); e0 = r * e0 + (1.0 - r) * (1.0 - e0); } return e0; } /* main */ int main() { int n; scanf("%d%lf%lf%lf%s", &n, &p, &q, &r, s); char *cpt = s; double e = expr(cpt); printf("%d\n", (int)(e * 100)); return 0; }