hdu4336 概率dp
来源:互联网 发布:律师 防身用具 知乎 编辑:程序博客网 时间:2024/06/05 21:13
http://acm.hdu.edu.cn/showproblem.php?pid=4336
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.
Input
The first line of each test case contains one integer N (1 <= N <= 20), indicating the number of different cards 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 most one card in a bag of snacks. And it is possible that there is nothing in the bag.
Note there is at most one card in a bag of snacks. And it is possible that there is nothing in the bag.
Output
Output one number for each test case, indicating the expected number of bags to buy to collect all the N different cards.
You will get accepted if the difference between your answer and the standard answer is no more that 10^-4.
You will get accepted if the difference between your answer and the standard answer is no more that 10^-4.
Sample Input
10.120.1 0.4
Sample Output
10.00010.500
/**hdu 4336 概率dp、状态压缩dp题目大意:有N(1<=N<=20)张卡片,每包中含有这些卡片的概率为p1,p2,````pN. 每包至多一张卡片,可能没有卡片。 求需要买多少包才能拿到所以的N张卡片,求次数的期望。解题思路:状态压缩求概率。 dp[(1<<n)-1]=0,dp[i]=(sum(dp[i|(1<<j)]*a[j])+1)/(sum(a[j]));j为所有j&(1<<i)==0,dp[0]即为所求*/#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>using namespace std;int n;double a[30],dp[(1<<20)+3];int main(){ while(~scanf("%d",&n)) { double ans=1.0; for(int i=0;i<n;i++) { scanf("%lf",&a[i]); ans-=a[i]; } int maxx=(1<<n)-1; dp[maxx]=0.0; for(int i=maxx-1;i>=0;i--) { double cnt=0,sum=1; for(int j=0;j<n;j++) { if(i&(1<<j)) cnt+=a[j]; else sum+=dp[i|(1<<j)]*a[j]; } dp[i]=sum/(1-cnt-ans); } printf("%.5lf\n",dp[0]); } return 0;}
1 0
- 概率dp hdu4336 递推法
- hdu4336概率dp
- hdu4336 概率dp
- ACM 概率DP hdu4336
- 概率dp+状态压缩HDU4336
- 【HDU4336】【Card Collector】【概率dp】
- 概率dp HDU4336 Card Collector
- hdu4336(壮压DP&概率DP)
- hdu4336(概率DP+状态压缩)
- hdu4336 Card Collector 状压+概率DP
- HDU4336-Card Collector(概率DP求期望)
- hdu4336(概率DP+状态压缩)
- hdu4336 Card Collector 概率dp(或容斥原理?)
- [HDU4336]Card Collector(概率期望+状压dp)
- hdu4336(状压dp求期望)
- hdu4336 状态压缩dp+概率论
- hdu4336 Card Collector 状态压缩dp
- hdu4336之状态压缩慨率DP
- android快速查找代码引用
- HTML5开发Android
- 在html页面中直接嵌入图片数据
- TextView测试对邮件的连接
- C时间函数ctime返回值的探讨
- hdu4336 概率dp
- 天津哪里治疗前列腺炎最好
- linux下的性能查询命令
- AI 快捷键大全
- C++中extern “C”
- http协议基础详解
- Strumpy Shader Editor入门教程
- xml与json区别
- 幻立方解法之暴力求解