题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4336

题目大意:有n种卡片,需要吃零食收集,打开零食,出现第i种卡片的概率是p[i],也有可能不出现卡片。问你收集齐n种卡片,吃的期望零食数是多少?

状态压缩:f[mask],代表收集齐了mask,还需要吃的期望零食数。

打开包装,有3种情况,第一种:没有卡片,概率(1-sigma(p[i]))

第二种,在已知种类中:概率sigma(p[j])

第三种,在未知种类中:p[k]

因此 f[mask] = f[mask]*(1-sigma(p[i])) + f[mask] * sigma(p[j]) + sigma(f[mask|k]*p[k]) + 1

 ///#pragma comment(linker, "/STACK:102400000,102400000")
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <cmath>
#include <numeric>
#include <iterator>
#include <iostream>
#include <cstdlib>
#include <functional>
#include <queue>
#include <stack>
#include <string>
#include <cctype>
using namespace std;
#define PB push_back
#define MP make_pair
#define SZ size()
#define ST begin()
#define ED end()
#define CLR clear()
#define ZERO(x) memset((x),0,sizeof(x))
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
const double EPS = 1e-; const int MAX_N = ;
int N;
double p[MAX_N+],f[<<MAX_N]; int main(){ while( ~scanf("%d",&N) ) {
ZERO(f);
double sum = 0.0;
for(int i=;i<=N;i++){
scanf("%lf",&p[i]);
sum += p[i];
}
f[(<<N)-] = ;
for( int mask=(<<N)-;mask>=;mask-- ){
double p1 = ;
for(int i=;i<N;i++){
if( (mask>>i)& ) {
p1 += p[i+];
}
}
// printf("p1 = %f\n",p1);
double p2 = ;
for(int i=;i<N;i++){
if( !((mask>>i)&) ) {
p2 += f[mask|(<<i)]*p[i+];
// printf("f[mask|(1<<i)]=%f\n",f[mask|(1<<i)]);
}
}
// printf("p2 = %f\n",p2);
f[mask] = (p2+1.0)/(sum-p1);
}
printf("%.10f\n",f[]);
} return ;
}

[HDU 4336] Card Collector (状态压缩概率dp)的更多相关文章

  1. HDU 4336 Card Collector(动态规划-概率DP)

    Card Collector Problem Description In your childhood, do you crazy for collecting the beautiful card ...

  2. HDU 4336 Card Collector (期望DP+状态压缩 或者 状态压缩+容斥)

    题意:有N(1<=N<=20)张卡片,每包中含有这些卡片的概率,每包至多一张卡片,可能没有卡片.求需要买多少包才能拿到所以的N张卡片,求次数的期望. 析:期望DP,是很容易看出来的,然后由 ...

  3. HDU 4336 Card Collector 期望dp+状压

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4336 Card Collector Time Limit: 2000/1000 MS (Java/O ...

  4. hdu 4336 Card Collector(期望 dp 状态压缩)

    Problem Description In your childhood, people in the famous novel Water Margin, you will win an amaz ...

  5. HDU 4336——Card Collector——————【概率dp】

    Card Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  6. hdu 4336 Card Collector (概率dp+位运算 求期望)

    题目链接 Card Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  7. HDU 4336 Card Collector:状压 + 期望dp

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4336 题意: 有n种卡片(n <= 20). 对于每一包方便面,里面有卡片i的概率为p[i],可 ...

  8. hdu4336 Card Collector 状态压缩dp

    Card Collector Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...

  9. hdu 4649 Professor Tian 反状态压缩+概率DP

    思路:反状态压缩——把数据转换成20位的01来进行运算 因为只有20位,而且&,|,^都不会进位,那么一位一位地看,每一位不是0就是1,这样求出每一位是1的概率,再乘以该位的十进制数,累加,就 ...

随机推荐

  1. javascript下ie7,ie8的Date Bug的解决

    ie9+, chrome firefox opera下 string到Date 使用  new Date("2013-01-01"); 都是ok的. 但在ie7, ie8下 返回N ...

  2. 【转】DBMS_STATS.GATHER_TABLE_STATS详解

    转自http://blog.itpub.net/26892340/viewspace-721935/ [作用] DBMS_STATS.GATHER_TABLE_STATS统计表,列,索引的统计信息(默 ...

  3. 如何制作快速加载的HTML页面

    整理出来的tip 减小页面的大小 在页面下载中,页面的大小至今扮演着非常重要的因素. 减小页面的大小能够通过排除不必要空格,注释,动态内嵌脚本,和放入外部文件的 CSS 等在页面结构中很小的改变都能够 ...

  4. jquery的ajax和jsonp的写法

    交互 ajax jsonp ajax跟之前一模一样 $(document).ready(function(){     $.ajax({         url:'get.php',         ...

  5. codeforces Expecting Trouble

    link:http://codeforces.com/contest/345/problem/A 写完这道题目才发现这场比赛只能用Ada语言提交== 好吧,逗我玩呢 考的是数学期望公式,二项分布的期望 ...

  6. Unix系统小知识(转)

    Unix操作系统的小知识 2.VI添加行号/翻页/清屏 .在对话模式时(即输完Esc再输入: ),输入“:set number”可以将编辑的文本加上行号.跟玩俄罗斯方块一样方便的上下左右移动箭头的快捷 ...

  7. 备忘DES简单加密与解密

    package com.ego.util; import java.io.IOException; import java.security.SecureRandom; import javax.cr ...

  8. linux apache 配置URL地址栏大小写不敏感配置

    1.apache配置 解决如下:把mod_speling.so放到apache目录下的 lib中... 然后修改http.conf文件, 加入:LoadModule speling_module /u ...

  9. pthread_cond_wait()函数的理解(摘录)

    /************pthread_cond_wait()的使用方法**********/pthread_mutex_lock(&qlock);    /*lock*/pthread_c ...

  10. 《C与指针》第十二章练习

    本章例程 //12.3 #include <stdio.h> #include <stdlib.h> typedef struct NODE{ struct NODE *lin ...