HDU4336 Card Collector 【容斥原理】【数学期望】
来源:互联网 发布:知乎 红楼梦 编辑:程序博客网 时间:2024/06/04 18:10
Card Collector
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.
Note there is at most one card in a bag of snacks. And it is possible that there is nothing in the bag.
You will get accepted if the difference between your answer and the standard answer is no more that 10^-4.
10.120.1 0.4
10.00010.500
题意:方便面里都可以吃出卡片,吃出每种卡片的概率已给出,问你集齐一套卡片的期望
思路:这个只要会算期望了,基本解决,弱的我连期望也不会了,概率学的圈还回去了
给出一组样例解释,一点即懂,类似于gcd那个题目,Goal=每张卡片的期望-两张卡片的期望+三张……
每张卡片的期望就等于1/p[i],
以样例二为例,集齐单张卡片的期望 temp[1|1]=1/0.1=10 temp[1|2]=1/0.4=2.5
集齐两张temp[2|1,2]=1/(0.1+0.4)=2
ans=temp[1]-temp[2]=12.5-2=10.5
3 0.1 0.2 0.3
temp[1|1]=10 temp[1|2]=5 temp[1|3]=3.333
temp[2|1,2]=3.333 temp[2|1,3]=2.5 temp[2|2,3]=2
tenp[3|1,2,3]=1.6666
10+5-3.333+3.333-2.5-2+1.66=12.166
#include<iostream>#include<stdio.h>#include<string.h>#include<cmath>#include<algorithm>using namespace std;#define ll long long#define MOD 1000000007#define N 110double p[N];int main(){ int n; while(scanf("%d",&n)!=EOF) { double sum=0; for(int i=0;i<n;i++) { scanf("%lf",&p[i]); sum+=p[i]; } double ans=0; for(int i=1;i<(1<<n);i++) { int cnt=0; double sum=0; for(int j=0;j<n;j++) if(i&(1<<j)) { sum+=p[j]; cnt++; } if(cnt&1)ans+=1.0/sum; else ans-=1.0/sum; } printf("%.5lf\n",ans); } return 0;}
阅读全文
0 0
- HDU4336 Card Collector 【容斥原理】【数学期望】
- hdu4336 Card Collector (容斥原理)
- HDU4336 Card Collector【容斥原理】
- HDU 4336 Card Collector 数学期望(容斥原理)
- hdu4336 Card Collector 概率dp(或容斥原理?)
- hdu 4336 Card Collector (期望dp|容斥原理)
- HDU4336-Card Collector(概率DP求期望)
- hdu4336 Card Collector(期望dp)
- HDU 4336 Card Collector (容斥 期望)
- HDU 4336 Card Collector(容斥原理 or 状压求期望dp)
- HDU 4336 Card Collector(状压期望DP || 容斥原理)
- [HDU4336]Card Collector(概率期望+状压dp)
- 【HDU4336】Card Collector-状态压缩DP+期望DP
- hdu 4336 Card Collector (容斥原理)
- HDU4336 Card Collector
- HDU4336 Card Collector
- hdu4336-----Card Collector
- hdu4336 Card Collector
- DFS的递归实现
- 零基础掌握百度地图兴趣点获取POI爬虫(python语言爬取)(安装篇、python、第三方库)
- VMware三种网络模式笔记
- 在北京做外包,月薪2万,还想提升,怎么办
- 《程序员的成长课》:少走5年弯路
- HDU4336 Card Collector 【容斥原理】【数学期望】
- 连接redis数据库 详解 (jedis工具类封装讲解特别好)
- 如何使用cmd运行Java程序
- C++使用sort通过cmp实现对结构体的排序
- Aladdin and the Flying Carpet LightOJ
- Mysql 查看连接数,状态
- const、引用
- 实习总结
- C语言面试题12.2