Hdu4336 card collector probability dp (or is the principle of rejection ?)

Source: Internet
Author: User

Question:

Buy a complete set of cards to win the grand prize. There is a card or no card in each packaging bag.

The probability P [I] of each card and the number of all card types N (1 <=n <= 20) are known ).

Ask the expected value of the number of cards to buy.

At the beginning, the expected value I understood was a previously learned value * the probability of its own occurrence. That's right, but I don't know what the value is in this question.

After thinking and struggling, I finally understood that the minimum number of packages to be purchased is the value you asked. It is difficult to understand but important,

In this question, set N to DP [0]

You can think like this: you need to buy a sum package to collect N types of cards, then the last package you bought must win, that is, it must be one of N types,

It is represented by State compression. DP [1111111] indicates that you can now ask for a packet in N, that is, it can be changed to 011111111,1011111, 1101111 .... Status in 1111110

DP [1111111] = the probability that all States in the preceding column are multiplied by the packet of 0, that is, DP [I] + = DP [I | (1 <j)] * P [J];

DP [1111111] indicates that at the beginning, you can use either of them. The expected value is 0, because you do not have either of them,

DP [0000000], that is, DP [0], indicates that each package is available now. You don't need to buy it anymore. intuitively, you can understand that every package is 0. You have no choice,

Then, the initial value DP [(1 <n)-1] = 0,

From this point on, each bit of a state is listed. If it is 0, it can be changed to the status where the bit is 1,

Well, that's almost the case ..

I don't know whether my understanding is correct. I think the key is the significance of the expected value and the significance of the final result ..

I can only understand this step.

There's not much to think about the solution to the refresh principle. You can use Baidu to look simple.

The following is a referenceCodeFor more information, see

# Include <iostream> # include <cstdio> # include <cmath> # include <cstring> # include <algorithm> # include <string> using namespace STD; Double P [25], DP [1 <20]; int main () {int I, j, N; double pp; while (~ Scanf ("% d", & N) {for (I = 0; I <n; I ++) scanf ("% lf", & P [I]); DP [(1 <n)-1] = 0; for (I = (1 <n)-2; I> = 0; I --) // enumerate all statuses {pp = 0; DP [I] = 1; for (j = 0; j <n; j ++) // enumerate every bit {If (! (I & (1 <j) // this bit is 0 {DP [I] + = DP [I | (1 <j)] * P [J]; pp + = P [J];} DP [I]/= pp; // all the statuses that can reach the I state are found. The sum of the expected values in the loop is the probability and} printf ("% lf \ n", DP [0]);} return 0 ;}

Related Article

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.