HDU 4649 worker sor Tian (reverse state compression DP, probability)

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.