Test instructions
There are N (1<=N<=20) cards, the probability of each package containing these cards is P1,P2, "" PN.
At most one card per pack, there may be no cards.
Ask how many bags you need to buy so that you can get the N cards and expect the number of times.
Transfer equation: F[s] = 1 + ((1-segma{P[i]}) F[s]) + (segma{P[j]*f[s]}) + (segma{p[k]*f[s| ( 1<<k)]})
The move item can be:
segma{P[i]}f[s] = 1 + segma{p[i]*f[s| ( 1<<i)},i= I card not collected
1#include <cstdio>2#include <iostream>3#include <algorithm>4#include <cstring>5#include <cmath>6#include <queue>7#include <map>8 using namespacestd;9 #defineMOD 1000000007Ten Const Doubleeps=1e-5; One #defineCL (a) memset (A,0,sizeof (a)) A #defineTS printf ("*****\n"); - Const intmaxn= A; - intN,m,tt; the DoubleA[MAXN]; - Doubledp[1<< A]; - intMain () - { + inti,j,k; - #ifndef Online_judge +Freopen ("1.in","R", stdin); A #endif at while(SCANF ("%d", &n)! =EOF) - { - Doublett=0; - for(i=0; i<n;i++) scanf ("%LF", &a[i]), tt+=A[i]; -dp[(1<<n)-1]=0; -tt=1-tt; in for(I= (1<<n)-2; i>=0; i--) - { to Doublesum=1, x=0; + for(j=0; j<n;j++) - { the if(i& (1<<j)) * { $X+=A[J];//The cards that came up were originallyPanax Notoginseng } - Else the { +Sum+=a[j]*dp[i| (1<<j)]; A } the } +dp[i]=sum/(1-tt-x); - } $printf"%.5lf\n", dp[0]); $ } - return 0; -}
HDU 4336 probability DP