[min-max容斥][dfs] Hdu P4336 Card Collector
Posted comfortable
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[min-max容斥][dfs] Hdu P4336 Card Collector相关的知识,希望对你有一定的参考价值。
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.
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的主要内容,如果未能解决你的问题,请参考以下文章