Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=4336
Test instructions: To set up n different cards, give each card probability, ask you to collect n cards to buy the number of cards to expect
First of all, here the probability is at the same time, and the probability of different steps to make a difference, many people are limited to the idea here.
At least get a desired value of a card + at least a B card expectations-at least one card to get the desired value = = at least to get a card and B card expectations, this is the case of two cards, here I focus on this situation: for example, 0.1 0.4, if we want to get at least the first card, then we must meet 1/0.1 =10, and if you want to get at least the second one, you have to meet 1/0.4=2.5, some people will say if I drew the first card, there are 9 left, can be assigned to the second take? Here, it is important to note that here is the same time to take the total card, which is obtained separately, that is, you get the first card case, the probability of obtaining a second card, which is the conditional probability, is obtained separately. We are here to get the total card at the same time, we now take the 1/10+1/0.4=12.5, and here at the same time, in the case of 10 contains a card or B Card 1/(0.1+0.4), in 2.5 contains a card or B card is expected to 1/(0.1+0.4) = 2, Think about why the denominator of a or B card here is 1, because we're asking for at least A or B card, considering at least, that is, getting the desired minimum, so it's 1. Then: 1/0.1+1/0.4-(1/(0.1+0.4)) ==10.500;
Similarly, push down to N, as well, according to the principle of Achieva medical, the reduction of even.
Push down to n get 1/p1+1/p2+......+1/pn-(1/(P1+P2) +1/(P2+P3) +......+1 (PN+P1)) +1/(P1+P2+P3) +......+1/(P1+P2+P3) +......+1/(Pn-1+Pn+P1) + ... (-1) (n-1)/(P1+P2+P3+......+PN);
1#include <algorithm>2#include <iostream>3#include <cstdlib>4#include <cstring>5#include <cstdio>6#include <vector>7#include <cmath>8#include <queue>9#include <Set>Ten#include <map> One #defineINF 0x3f3f3f3f A using namespacestd; -typedefLong LongLL; - the Doublep[ -]; - intMain () - { - intN; + while(~SCANF ("%d", &N)) - { + for(inti =0; I < n; i++) Ascanf"%LF", &p[i]); at Doubleres =0; - for(inti =1; I < (1<< N); i++) - { - intsum =0; - DoubleTe =0; - for(intj =0; J < N; J + +) in { - if((1<< j) &i) to { +sum++; -Te + =P[j]; the } * } $ if(Sum &1)Panax NotoginsengRes + =1.0/te; - Else theRes-=1.0/te; + } Aprintf"%lf\n", res); the } + return 0; -}
View Code
Hud4336_ Tolerance DP