题目链接: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. 【 D3.js 进阶系列 — 6.1 】 缩放的应用(Zoom)

    缩放(Zoom)是另一种重要的可视化操作,主要是使用鼠标的滚轮进行. 1. zoom 的定义 缩放是由 d3.behavior.zoom() 定义的. var zoom = d3.behavior.z ...

  2. matlab 批量提取CNN特征

    无类别,图像混合放置: clear close all addpath ./matlab model= './models/bvlc_reference_caffenet/deploy.prototx ...

  3. C++ 虚函数,纯虚函数的一些问题

    #include <iostream> using namespace std; #define cendl cout << endl; class AA{//这是一个纯虚函数 ...

  4. myeclipse里的调试快捷键

    好多时候在调试代码时,有的时候只会用F5,其他的快捷键却一概不知.今天百度查了一下其他快捷键调试的作用,总结如下 F5 (setp into ): 跳入当前执行的方法中 F6 (step over): ...

  5. Tomcat version 6.0 only supports J2EE 1.2, 1.3, 1.4, and Java EE 5 Web modules的解决办法

    前提:用eclipse做项目,新建“Dynamic Web Project”时,“Dynamic web module version”栏里选了3.0版本,部署项目的时候出现了如题的错误. 解决办法: ...

  6. 通过全局getApp获取全局实例获取数据

    学习是每一个人都要面对的铁一般的事实,不进则退.学习同样讲究途径和方法,面对知识这个巨人,我们永远不会有成年的那一刻,但我们可以让自己毕生尽可能地吸取更多有价值的信息,好让自己人生充满各种“意义”存在 ...

  7. css实现分割线

    <!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>& ...

  8. ubuntu 安装git服务器

    ubuntu14.04安装git,搭建环境 1.sudo apt-get install git 2.生成key ssh-keygen -t rsa 3.保存其他用户,创建的ssh用户密码 cd .s ...

  9. WPF-流文档元素

    1.Block元素 用于分组其他元素 Paragraph是块级别元素,文本段落 Paragraph.Inlines集合内. 设置第一行缩进量Paragraph.TextIndet 2.Inline元素 ...

  10. 怎么查看bios版本

    怎么查看bios版本呢?无需去注册表查看,无需去BIOS中查看,只需要一条简单的命令即可,下面就来一起看一看怎么查看bios版本: Win键+R打开“运行”,然后再“运行”中输入cmd进而打开“cmd ...