Card CollectorTime
limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 2141 Accepted Submission (s): 1008
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
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <string > #include <queue> #include <algorithm> #include <map> #include <cmath> #include <iomanip > #define INF 99999999typedef long ll;using namespace Std;const int max= (1<<20) +10;const double Eps=1e-4;int N;double Dp[max],p[max];int Main () {while (~SCANF ("%d", &n)} {double p2=1; for (int i=0;i<n;++i) {scanf ("%lf", &p[i]);p 2-=p[i];} int bit=1<<n;dp[bit-1]=0;for (int i=bit-2;i>=0;--i) {double p1=p2,ans=0;for (int j=0;j<n;++j) {if (i& (1 <<J) {//j This card exists p1+=p[j];} else{ans+=p[j]* (dp[i+ (1<<j)]+1);} dp[i]= (ANS+P1)/(1-P1);}} printf ("%.4f\n", dp[0]);//Keep 4 decimal places here because of the topic last sentence}return 0;}
Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.
hdu4336 compression rate generous state DP