HDU 4336 Card Collector (probabilistic DP)

Source: Internet
Author: User



Test instructions: There are n kinds of cards, eating snacks when you will eat some cards, tell you in a bag of snacks to eat each card of the probability, to collect all the cards need to buy a snack bag number of expectations.

Idea: First state compression, then probability DP

The state transition equation is d[i] = P ' * (d[i]+1) + sigma (d[i |, using d[i] to indicate how many packets need to be bought by the state I to the target. (1 << j) * P[i]), then the same item is moved to the left and the answer is finally available.

#include <cstdio>  #include <cstring>  #include <cmath>  #include <cstdlib>  # include<iostream>  #include <algorithm>  #include <vector>  #include <map>  # include<queue>  #include <stack> #include <string> #include <map> #include <set># Define EPS 1e-6 #define LL long Long  #define PII pair<int,int>using namespace std;  const int MAXN = + 5;//const int INF = 0x3f3f3f3f;//freopen ("Input.txt", "R", stdin);d ouble p[25];d ouble d[1<< 21];int Main () {int n;while (scanf ("%d", &n) = = 1) {Double no = 1; for (int i = 0; i < n; i++) {scanf ("%lf", &p[i ]); no-= P[i];}  int s = (1 << n) -1;d[s] = 0;for (int i = s-1; I >= 0; i--) {Double TP = no;d[i] = no;for (int j = 0; J < N; j + +) {if (1<<j) &i) {TP + p[j];d [i] + = P[j];} else D[i] + = p[j]* (d[i| ( 1<<J)]+1);} D[i] = d[i]/(1-TP);} printf ("%.6lf\n", D[0]);} return 0;}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

HDU 4336 Card Collector (probabilistic DP)

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.