hdu4336 Card Collector(期望dp)
2016-10-11 15:23
429 查看
hdu4336
题目
就是小时候的集卡,有N张卡,给出每张卡获得的概率,有可能没有卡,问开包的期望。思路
概率正推期望逆推,用状态压缩表示拿到不用的卡片的期望值。开了一包还是自己的概率是当前状态有的卡的概率与开不到卡的概率和。不是自己的期望是所有当前能转移的状态的期望*由什么卡转来的概率的和+1。dp[i]-dp[i]*myself=tot+1代码
#include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <cstring> using namespace std; typedef long long ll; const int maxn=1<<20; int n; double p[25]; double none; double dp[maxn],pp[maxn]; void pre() { for(int i=0; i<(1<<n); i++) { pp[i]=none; for(int j=0; j<n; j++) { if(i&(1<<j)) pp[i]+=p[j]; } } } int main() { while(scanf("%d",&n)!=EOF) { none=0; for(int i=0; i<n; i++) { scanf("%lf",&p[i]); none+=p[i]; } none=1-none; pre(); dp[(1<<n)-1]=0; for(int i=(1<<n)-2; i>=0; i--) { double tot=0; for(int j=0; j<n; j++) { if(!(i&(1<<j))) { tot+=dp[i|(1<<j)]*p[j]; } } dp[i]=(tot+1)/(1-pp[i]); } printf("%.4lf\n",dp[0]); } return 0; }
相关文章推荐
- HDU4336-Card Collector(概率DP求期望)
- [HDU4336]Card Collector(概率期望+状压dp)
- [HDU] 4336 Card Collector 期望dp
- hdu 4336 Card Collector (期望dp|容斥原理)
- hdu 4336 Card Collector(期望 dp 状态压缩)
- 期望dp-hdu-4336-Card Collector
- 【HDU4336】Card Collector (动态规划,数学期望)
- 期望dp-hdu-4336-Card Collector
- 【HDU4336】Card Collector (动态规划,数学期望)
- hdoj 4336 card collector(状态压缩dp求数学期望)
- HDU 4336 Card Collector (期望DP+状态压缩 或者 状态压缩+容斥)
- hdu 4336 Card Collector(期望+状压DP)
- HDU 4336 Card Collector(容斥原理 or 状压求期望dp)
- HDU 4336 Card Collector(状压期望DP || 容斥原理)
- 【HDU4336】【Card Collector】【概率dp】
- hdu4336 Card Collector 概率dp(或容斥原理?)
- hdu4336(状压dp求期望)
- hdu-4336 Card Collector状态压缩|期望dp】
- hdu4336 Card Collector 状态压缩dp
- Card Collector - HDU 4336 状压期望dp