The question of probability DP, which has never been done on such topics.
Dp[s] means that when the state is s the time to buy more cards can buy the whole, represents a desired value.
Dp[s] = 1 + P (empty) * Dp[s] + p (had) * Dp[s] + p (new) * Dp[nst].
Thus the dp[s] can be solved.
1 /*4336*/2#include <iostream>3#include <sstream>4#include <string>5#include <map>6#include <queue>7#include <Set>8#include <stack>9#include <vector>Ten#include <deque> One#include <algorithm> A#include <cstdio> -#include <cmath> -#include <ctime> the#include <cstring> -#include <climits> -#include <cctype> -#include <cassert> +#include <functional> -#include <iterator> +#include <iomanip> A using namespacestd; at //#pragma COMMENT (linker, "/stack:102400000,1024000") - - #defineSTI set<int> - #defineStpii Set<pair<int, int> > - #defineMpii map<int,int> - #defineVI vector<int> in #definePII pair<int,int> - #defineVpii vector<pair<int,int> > to #defineRep (I, A, n) for (int i=a;i<n;++i) + #definePer (i, a, n) for (int i=n-1;i>=a;--i) - #defineCLR Clear the #definePB Push_back * #defineMP Make_pair $ #defineFIR FirstPanax Notoginseng #defineSEC Second - #defineAll (x) (x). Begin (), (x). End () the #defineSZ (x) ((int) (x). Size ()) + #defineLson L, Mid, rt<<1 A #defineRson mid+1, R, rt<<1|1 the + Const intMAXN = -; - DoubleP[MAXN]; $ Doubledp[1<<MAXN]; $ intN; - - voidsolve () { the intMST =1<<N; - intmask = MST-1;WuyiDp[mask] =0; the -Per (I,0, Mask) { Wu DoubleTMP =0.0; - AboutDp[i] =1.0; $Rep (J,0, N) { - if(I & (1<<j)) - Continue; -Dp[i] + = p[j] * dp[i| (1<<j)]; ATMP + =P[j]; + } theDp[i]/=tmp; - } $ the DoubleAns = dp[0]; theprintf"%.06lf\n", ans); the } the - intMain () { inIos::sync_with_stdio (false); the #ifndef Online_judge theFreopen ("data.in","R", stdin); AboutFreopen ("Data.out","W", stdout); the #endif the the while(SCANF ("%d", &n)! =EOF) { +Rep (I,0, N) -scanf"%LF", &p[i]); the solve ();Bayi } the the #ifndef Online_judge -printf"Time =%d.\n", (int) clock ()); - #endif the the return 0; the}
"Hdoj" 4336 Card Collector