# Include <iostream> # include <stdio. h> # include <algorithm> # include <cmath> # include <string. h> using namespace std; # define Maxn 210int A [Maxn]; double p [Maxn]; char str [Maxn]; int Arr [Maxn] [25]; double f [Maxn] [2]; int n; void Bit (int x) <SPAN style = "WHITE-SPACE: pre "> </SPAN> // convert the number of current locations to binary {int t = 0; int tt = A [x]; while (tt) {Arr [x] [t ++] = tt & 1; tt >>=1 ;}} void Solve (int x) {int I, j; memset (f, 0, sizeof (f); if (Arr [0] [x]) F [0] [1] = 1; else f [0] [0] = 1; for (I = 1; I <= n; I ++) {f [I] [1] = f [I-1] [1] * p [I]; <SPAN style = "WHITE-SPACE: pre "> </SPAN> // If no, then the probability of the Current Position 01 is the probability of the previous position 01 f [I] [0] = f [I-1] [0] * p [I]; if (str [I] = '&') {<SPAN style = "WHITE-SPACE: pre"> </SPAN> // according to &, |, ^ returns the probability of the current 01 if (Arr [I] [x]) {f [I] [1] + = f [I-1] [1] * (1-p [I]); f [I] [0] + = f [I-1] [0] * (1-p [I]);} else {f [I] [0] + = f [I-1] [1] * (1-p [I]); f [I] [0] + = f [I-1] [0] * (1-p [I]);} if (str [I] = '| '){ If (Arr [I] [x]) {f [I] [1] + = f [I-1] [1] * (1-p [I]); f [I] [1] + = f [I-1] [0] * (1-p [I]);} else {f [I] [1] + = f [I-1] [1] * (1-p [I]); f [I] [0] + = f [I-1] [0] * (1-p [I]);} if (str [I] = '^ ') {if (Arr [I] [x]) {f [I] [0] + = f [I-1] [1] * (1-p [I]); f [I] [1] + = f [I-1] [0] * (1-p [I]);} else {f [I] [0] + = f [I-1] [0] * (1-p [I]); f [I] [1] + = f [I-1] [1] * (1-p [I]); }}/ * Because bitwise operations do not affect carry, therefore, you only need to calculate the probability of 1 occurrence for each digit. When solving the expectation, convert it to a 10-digit system. */Int main () {int I, j, tt = 1; while (~ Scanf ("% d", & n) {memset (Arr, 0, sizeof (Arr); for (I = 0; I <= n; I ++) {scanf ("% d", & A [I]); Bit (I) ;}getchar (); for (I = 1; I <= n; I ++) {str [I] = getchar (); getchar () ;}for (I = 1; I <= n; I ++) scanf ("% lf ", & p [I]); double ans = 0; int tmp = 1; for (I = 0; I <20; I ++) {Solve (I ); ans + = tmp * f [n] [1]; tmp <= 1;} printf ("Case % d: \ n", tt ++ ); printf ("% 0.6lf \ n", ans);} return 0 ;}