"Hdoj" 4336 Card Collector

Source: Internet
Author: User

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

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.