Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 4336
There are N types of cards. Each bag of snacks contains at most one card, which gives the probability of each card in a bag of snacks. Ask how many bags of snacks can be collected to all the cards on average.
Status is compressed. There are 1 <n-1 statuses, and DP [sta] indicates the average number of snacks bought from the current status to the target status, it is known that the final state DP [1 <n-1] = 0, DP [sta] can be obtained from the following State:
There is no card in this bag of snacks, the probability is P (the probability that there is no card), the status is transferred to sta;
This bag of snacks contains card J, but he already owns this card, probably a [J], and the status is changed to sta;
This bag of snacks contains card J, which has never been used before. The probability is a [J] and the status is transferred to sta | (1 <j)
Push back.
# Include <stdio. h> # include <iostream> # include <map> # include <set> # include <list> # include <stack> # include <vector> # include <math. h> # include <string. h> # include <queue> # include <string> # include <stdlib. h> # include <algorithm> // # define ll _ int64 # define ll long # define EPS 1e-9 # define PI ACOs (-1.0) using namespace STD; const int INF = 0x3f3f3f; const int maxn = 4010; double DP [1100000]; Double A [22]; In T Main () {int N; while (~ Scanf ("% d", & N) {double T = 0; For (INT I = 0; I <n; I ++) {scanf ("% lf ", & A [I]); t + = A [I];} t = 1-T; memset (DP, 0, sizeof (DP )); int M = (1 <n)-1; DP [m] = 0; For (INT sta = m-1; STA> = 0; sta --) {double S1 = 0, s2 = 0; For (Int J = 0; j <n; j ++) {If (! (STA & (1 <j) {S1 + = A [J] * DP [sta | (1 <j)];} elses2 + = A [J];} S1 + = 1; DP [sta] = S1/(1-s2-t);} printf ("%. 4lf \ n ", DP [0]);} return 0 ;}
HDU 4336 card collector (expected)