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

本文探讨了童年时期收集零食卡片的数学问题,通过min-max反演理论计算收集完整套卡片所需的预期零食购买数量,提供了详细的解析过程及C++代码实现。

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 }

 

转载于:https://www.cnblogs.com/Comfortable/p/11335364.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值