hdu4336-----Card Collector

Source: Internet
Author: User

Card Collector Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 2785 Accepted Submission (s): 1321
Special Judge


Problem DescriptionIn your childhood, do you crazy for collecting the beautiful cards in the snacks? They said that, for example, if you collect all the 108 people in the famous novel Water Margin, you'll win an amazing a Ward.

As a smart boy, you notice this to win the award, you must buy much more snacks than it seems to be. To convince your friends don't to waste money any more, you should find the expected number of snacks one should buy to Coll ECT a full suit of cards.
Inputthe first line of all test case contains one integer n (1 <= n <=), indicating the number of different card s you need the Collect. The second line contains N numbers p1, p2, ..., pn, (p1 + p2 + ... + pN <= 1), indicating the possibility of each card To appear in a bag of snacks.

Note there is at the most one card in a bag of snacks. And it is possible this there is nothing in the bag.
Outputoutput one number for each test case, indicating the expected number of bags to buy to collect all the N different C Ards.

You'll get accepted if the difference between your answer and the standard answer are no more that 10^-4.
Sample Input
10.120.1 0.4

Sample Output
10.00010.500

Source2012 multi-university Training Contest 4
Recommendzhoujiaqi2010 | We have carefully selected several similar problems for you:4337 4331 4332 4333 4334

Simple probability dp, found n up to only 20, so state compression to get it done
Dp[i] means that the desired value of the card is bought when the card is in the status of I.
Ans = dp[0]
dp[(1 << N)-1] = 0;
The transfer equation is divided into 2 pieces, the first one is the card in this state, the second block is not in the state and the card is not bought

/************************************************************************* > File Name:hdu4336.cpp > Author: ALex > Mail: [email protected] > Created time:2014 December 23 Tuesday 14:48 32 seconds ******************************* /#include <map> #include <set> #include <queue> #include <stack> #include <vector> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <algorithm>using namespace std;const int N = (1 <<) + 10;i NT N;double Dp[n];d ouble p[30], vp;double dfs (int s) {if (Dp[s]! =-1) {return dp[s];} Double x = 0, y = 0;for (int i = 0; i < n; ++i) {if (!) ( S & (1 << i))//This state I did not draw {x + = p[i] * (DFS (s | (1 << i)) + 1);} Else{y + = P[i];}} Y + = Vp;return Dp[s] = (x + y)/(1-y);} int main () {while (~SCANF ("%d", &n)) {VP = 0;for (int i = 0; i < n; ++i) {scanf ("%lf", &p[i]), VP-= P[i];} VP + = 1;for (int i = 0; I <= (1 << N); ++i) {Dp[i] =-1.0;} dp[(1 << N)-1] = 0;printf ("%f\n", DFS (0)); return 0;}


hdu4336-----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.