码迷,mamicode.com
首页 > 其他好文 > 详细

[min-max容斥][dfs] Hdu P4336 Card Collector

时间:2019-08-11 16:46:33      阅读:99      评论:0      收藏:0      [点我收藏+]

标签:can   ast   tle   desc   names   must   scanf   str   eem   

Problem Description

In 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 will win an amazing award.
As a smart boy, you notice that to win the award, you must buy much more snacks than it seems to be. To convince your friends not to waste money any more, you should find the expected number of snacks one should buy to collect a full suit of cards.

 

题解

  • 设ti为第一次获得第i种卡片的期望时间,那么要求的就是E(max(ti))
  • 根据min-max反演可以得到E(max(s))=∑t∈s(-1)^(|T|-1)E(min(T))
  • 然后可以知道,E(min(T))=1/∑pi
  • 最后暴力出奇迹

 

代码

 1 #include <cstdio>
 2 #include <iostream>
 3 using namespace std;
 4 int n;
 5 double ans,p[30];
 6 void dfs(int d,double sum,double op)
 7 {
 8     if (d>n) { if (sum>1e-9) ans+=op/sum; return; }
 9     dfs(d+1,sum+p[d],-op),dfs(d+1,sum,op);
10 }
11 int main()
12 {
13     while (scanf("%d",&n)!=EOF)
14     {
15         for (int i=1;i<=n;i++) scanf("%lf",&p[i]);
16         ans=0,dfs(1,0,-1),printf("%.4lf\n",ans);
17     }
18 }

 

[min-max容斥][dfs] Hdu P4336 Card Collector

标签:can   ast   tle   desc   names   must   scanf   str   eem   

原文地址:https://www.cnblogs.com/Comfortable/p/11335364.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!