OpenJudge

05:Expected Value of an Expression

总时间限制:
1000ms
内存限制:
65536kB
描述

Given an expression as follows,

A0  O1   A1   O2   A2  …… On   An

Ai (0 <= i <= n) represents operands, Oi(1<= i <= n) represents operators. There are three types of operators including‘&’, '|' and '^', and they have the same priority. For each operator Oiand its incoming operand Ai, they may disappear together, and the probability for this disappearance is Pi.

Using the first case of the sample input, we illustrate the way to compute of the expected value:

(P1*P2)*A0+(1-P1)*(P2)*(A0O1A1)+(P1)*(1-P2)*(A0O2A2)+(1-P1)*(1-P2)*( A0O1A1O2A2)=0.1*0.2*1+0.9*0.2*(1^2)+0.1*0.8*(1^3)+0.9*0.8*(1^2^3)=0.72

输入
The input contains several test cases. For each test case, there is an integer n ( 0 < n <= 200 ) in the first line. In the second line, there are n+1 integers, representing {Ai}. The next line contains n operators , representing {Oi}. The forth line contains {Pi}. Ai is less than 2^20, 0<=Pi<=1.
输出
For each text case, you should output the text case number in the first line. Then, output the excepted value of the expression, round to 6 decimal places.
样例输入
2 
1 2 3 
^ ^ 
0.1 0.2 
2 
8 9 10 
^ ^ 
0.5 0.78
1 
1 2 
& 
0.5
样例输出
Case 1: 
0.720000 
Case 2: 
4.940000 
Case 3: 
0.500000

01 Use "long long" to calculate the answer
05 Expected Value of an Expression: Ai is less than 2^20

全局题号
15299
提交次数
11
尝试人数
7
通过人数
1