From http://blog.csdn.net/shuangde800
Question link: Click the open link
Theme
At first, there is a number a0, and then a total of N numbers A1, a2.. an are given. Each number of these N numbers has an operator, &, |, ^
And the probability of each digit is pi.
If a number appears, it uses its operators to perform bitwise operations with the preceding number.
What is the final expectation?
Ideas
The official answer to this question is anti-state compression.
Once you know how to express the status, it is not difficult to do it. 1a after the game.
The official question solution is already very detailed and is no longer cumbersome:
Back-state compression-converts data to 20-bit 01 for Computation
Because there are only 20 bits, and &, |, ^ are not carried, then one bit is regarded as one, and each bit is either 0 or 1, in this way, the probability of each digit being 1 is obtained, multiplied by the decimal number of the digit, and accumulated, which gives the overall expectation.
For each bit, the state transition equation is as follows:
F [I] [J] indicates the number of I prior to this bit. The probability of J (0 or 1) is calculated.
F [I] [1] = f [I-1] [1] * P [I] + calculate the probability of 1 based on the values of different operators and I bits.
F [I] [0] is the same.
Initial status: F [0] [0 ~ 1] = 0 or 1 (set based on the first number)
F [N] [1]
Code