hdu 4336

小吃包装袋里面有随机赠送一些有趣的卡片,如今你想收集齐 N 张卡片。每张卡片在食品包装袋里出现的概率是p[i] ( Σp[i] <= 1 ), 问你收集全部卡片所需购买的食品数量的期望是多少。

对于每袋食品。有两种结果,该卡片已经收集到了和没有收集到(没有卡片的情况视为收集到了)。

把已经收集到的卡片的集合记为 s ,dp[s] 表示已经收集到集合s的卡片情况下收集齐全部的卡片的购买数量的期望,s 为空集即为所求。s  为全集时dp[s] = 0;

对于上面说的两种情况 _si 表示集合 s 加入一个不在 s 中的卡片 i 的集合 Σ((dp[_si] + 1) * p[i]) ,而抽到已经收集到的卡片则是dp[s];

dp[s] = Σ((dp[_si] + 1) * p[i]) + dp[s] * (1 - Σ(p[i]));

而集合s我们能够用二进制非常好解决。

/***********************************************
** problem ID : poj_2096.cpp
** create time : Sat Jul 25 13:21:58 2015
** auther name : xuelanghu
** auther blog : blog.csdn.net/xuelanghu407
**********************************************/ #include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; int n, s;
double dp[1010][1010]; void init() {
for (int i=0; i<=n; i++) {
for (int j=0; j<=s; j++) {
dp[i][j] = -1.0;
}
}
} double DP(int i, int j) {
if (dp[i][j] != -1.0) return dp[i][j];
if (i == n && j == s) return dp[i][j] = 0.0; double res = 1.0;
if (i+1 <= n && j+1 <= s)
res += DP(i+1, j+1) * (n - i) * (s - j) * 1.0 / (n * s);
if (i+1 <= n)
res += DP(i+1, j) * (n-i) * j * 1.0 / (n * s);
if (j+1 <= s)
res += DP(i, j+1) * i * (s - j) * 1.0 / (n * s); return dp[i][j] = res / (1.0 - (i * j) * 1.0 / (n * s));
} int main () {
while (cin >> n >> s) {
init();
printf ("%.4lf\n", DP(0, 0));
}
return 0;
}

hdu 4336 概率dp + 状压的更多相关文章

  1. hdu 4336 Card Collector(状压dp/Min-Max反演)

    传送门 解题思路 第一种方法是状压\(dp\),设\(f(S)\)为状态\(S\)到取完的期望步数,那么\(f(S)\)可以被自己转移到,还可以被\(f(S|(1<<i))\)转移到,\( ...

  2. 20190716NOIP模拟赛T1 礼物(概率dp+状压)

    题目描述 夏川的生日就要到了.作为夏川形式上的男朋友,季堂打算给夏川买一些生 日礼物. 商店里一共有种礼物.夏川每得到一种礼物,就会获得相应喜悦值Wi(每种 礼物的喜悦值不能重复获得). 每次,店员会 ...

  3. HDU4336 Card Collector (概率dp+状压dp)

    http://acm.hdu.edu.cn/showproblem.php?pid=4336 题意:有n种卡片,一个包里会包含至多一张卡片,第i种卡片在某个包中出现的次数为pi,问将所有种类的卡片集齐 ...

  4. Educational Codeforces Round 13 E. Another Sith Tournament 概率dp+状压

    题目链接: 题目 E. Another Sith Tournament time limit per test2.5 seconds memory limit per test256 megabyte ...

  5. hdu 4336 概率dp

    题意:有N(1<=N<=20)张卡片,每包中含有这些卡片的概率为p1,p2,````pN.每包至多一张卡片,可能没有卡片.求需要买多少包才能拿到所以的N张卡片,求次数的期望. 转移方程: ...

  6. SCUT - 254 - 欧洲爆破 - 概率dp - 状压dp

    https://scut.online/p/254 思路很清晰,写起来很恶心. #include<bits/stdc++.h> using namespace std; #define l ...

  7. hdu 3247 AC自动+状压dp+bfs处理

    Resource Archiver Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 100000/100000 K (Java/Ot ...

  8. hdu 2825 aC自动机+状压dp

    Wireless Password Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  9. 【HDU】4352 XHXJ's LIS(数位dp+状压)

    题目 传送门:QWQ 分析 数位dp 状压一下现在的$ O(nlogn) $的$ LIS $的二分数组 数据小,所以更新时直接暴力不用二分了. 代码 #include <bits/stdc++. ...

随机推荐

  1. Java枚举的七种常见用法

    用法一:常量 在JDK1.5之前,我们定义常量都是:publicstaticfianl.....现在好了,有了枚举,可以把相关的常量分组到一个枚举类型里,而且枚举提供了比常量更多的方法. Java代码 ...

  2. Java中CAS详解

    在JDK 5之前Java语言是靠synchronized关键字保证同步的,这会导致有锁 锁机制存在以下问题: (1)在多线程竞争下,加锁.释放锁会导致比较多的上下文切换和调度延时,引起性能问题. (2 ...

  3. 使用 Golang 编写链代码 (v0.6 )

    https://www.ibm.com/developerworks/cn/cloud/library/cl-ibm-blockchain-chaincode-testing-using-golang ...

  4. 第三章 Typescript 基本数据类型

    Typescript 基本数据类型 一.基本数据类型 Boolean Number String Array Tuple Enum Any Void Null 和 Undefined Never 二. ...

  5. Gson Json 序列号 最常用的功能 MD

    Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...

  6. JAVA-jar包下载地址

    spring mvc常用jar包 commons-logging:http://commons.apache.org/proper/commons-logging/download_logging.c ...

  7. PHP使用DOM XML操作XML[总结]

    1.前言 XML树状层次结构鲜明,非常适合作为配置文件.PHP中可以使用DOM XML来操作XML.本文总结一下PHP使用DOM XML创建.添加节点.查询XML文件. 2.使用DOM XML XML ...

  8. 简单实现http proxy server怎么实现?

    原文:https://blog.csdn.net/dolphin98629/article/details/54599850 简单实现http proxy server怎么实现?

  9. rabbitmq页面出现/etc/rabbitmq/rabbitmq.config(not found)解决方法

    如果出现页面出现/etc/rabbitmq/rabbitmq.config(not found) 解决如下:find / -name "rabbitmq.config.example&quo ...

  10. [Docker] Hooking a Volume to Node.js Source Code

    Normally when you create a Volume, it will store in Docket Host, you can also tell the folder which ...