[poj2096] Collecting Bugs【概率dp 数学期望】
传送门:http://poj.org/problem?id=2096
题面很长,大意就是说,有n种bug,s种系统,每一个bug只能属于n中bug中的一种,也只能属于s种系统中的一种。一天能找一个bug,问找到的bug涵盖所有种类的bug与所有种类的系统期望需要几天。
令f(i, j)为找到了i种bug,j种系统期望的天数,那么今天再找一个bug,有4种情况:
①,bug种类为已找到的i种中的一种,系统种类为已找到的j种中的一种,则概率p1 = (i / n) * (j / s)
②,bug种类为未找到的(n - i)种中的一种,系统种类为已找到的j种中的一种,则概率p2 = ((n - i) / n) * (j / s)
③,bug种类为已找到的i种中的一种,系统种类为未找到的(s - j)种中的一种,则概率p3 = (i / n) * ((s - j) / s)
④,bug种类为未找到的(n - i)种中的一种,系统种类为未找到的(s - j)种中的一种,则概率p3 = ((n - i) / n) * ((s - j) / s)
则有f(i, j) = f(i, j) * p1 + f(i + 1, j) * p2 + f(i, j + 1) * p3 + f(i + 1, j + 1) * p4 + 1
即f(i, j) = ( f(i + 1, j) * p2 + f(i, j + 1) * p3 + f(i + 1, j + 1) * p4 + 1 ) / (1 - p1)
#include <cstdio> const int maxn = 1005, maxs = 1005; int n, s;
double f[maxn][maxs]; int main(void) {
scanf("%d%d", &n, &s);
for (int i = n; ~i; --i) {
for (int j = s; ~j; --j) {
if (i == n && j == s) {
continue;
}
f[i][j] = (f[i + 1][j] * (1 - (double)i / (double)n) * ((double)j / (double)s) +
f[i][j + 1] * ((double)i / (double)n) * (1 - (double)j / (double)s) +
f[i + 1][j + 1] * (1 - (double)i / (double)n) * (1 - (double)j / (double)s) + 1) / (1 - (double)(i * j) / (double)(n * s));
}
}
printf("%.4f\n", f[0][0]);
return 0;
}
[poj2096] Collecting Bugs【概率dp 数学期望】的更多相关文章
- POJ2096 Collecting Bugs(概率DP,求期望)
Collecting Bugs Ivan is fond of collecting. Unlike other people who collect post stamps, coins or ot ...
- poj 2096 Collecting Bugs (概率dp 天数期望)
题目链接 题意: 一个人受雇于某公司要找出某个软件的bugs和subcomponents,这个软件一共有n个bugs和s个subcomponents,每次他都能同时随机发现1个bug和1个subcom ...
- Poj 2096 Collecting Bugs (概率DP求期望)
C - Collecting Bugs Time Limit:10000MS Memory Limit:64000KB 64bit IO Format:%I64d & %I64 ...
- [POJ2096] Collecting Bugs (概率dp)
题目链接:http://poj.org/problem?id=2096 题目大意:有n种bug,有s个子系统.每天能够发现一个bug,属于一个种类并且属于一个子系统.问你每一种bug和每一个子系统都发 ...
- POJ 2096 Collecting Bugs (概率DP,求期望)
Ivan is fond of collecting. Unlike other people who collect post stamps, coins or other material stu ...
- Collecting Bugs (概率dp)
Ivan is fond of collecting. Unlike other people who collect post stamps, coins or other material stu ...
- poj 2096 Collecting Bugs 概率dp 入门经典 难度:1
Collecting Bugs Time Limit: 10000MS Memory Limit: 64000K Total Submissions: 2745 Accepted: 1345 ...
- POJ 2096 Collecting Bugs (概率DP)
题意:给定 n 类bug,和 s 个子系统,每天可以找出一个bug,求找出 n 类型的bug,并且 s 个都至少有一个的期望是多少. 析:应该是一个很简单的概率DP,dp[i][j] 表示已经从 j ...
- bzoj1415 [Noi2005]聪聪和可可【概率dp 数学期望】
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1415 noip2016 D1T3,多么痛的领悟...看来要恶补一下与期望相关的东西了. 这是 ...
随机推荐
- 表皮囊肿?wtf
https://baike.baidu.com/item/%E8%A1%A8%E7%9A%AE%E5%9B%8A%E8%82%BF/7852024?fr=aladdin
- spring mvc 集成freemarker模板
主要使用到的jar 文件:spring mvc +freemarker.jar 第一步:spring mvc 集成 freemarker <!-- 定义跳转的文件的前后缀 ,视图模式配置--&g ...
- hdu 1068 Girls and Boys(匈牙利算法求最大独立集)
Girls and Boys Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- VC++如何折叠代码
工具-选项,然后在文本编辑器,C/C++中的格式设置,把大纲语句块设置为True 这样之后,还是不能像C#一样使用region折叠代码,但是可以方法和if语句都会自动显示可以折叠. 使用#pr ...
- 【甘道夫】并行化频繁模式挖掘算法FP Growth及其在Mahout下的命令使用
今天调研了并行化频繁模式挖掘算法PFP Growth及其在Mahout下的命令使用,简单记录下试验结果,供以后查阅: 环境:Jdk1.7 + Hadoop2.2.0单机伪集群 + Mahout0.6 ...
- Redis 命令行 常用总结
http://www.redis.cn/commands.html# 1 Keys * 列出所有的keys redis > keys * ) "s:0" ) "o: ...
- Java使用三种不同循环结构对1+2+3+...+100 求和
▷//第一种求法,使用while结构 /** * @author 9527 * @since 19/6/20 */ public class Gaosi { public static void ma ...
- 嵌入式linux 实现mdev SD卡和U盘自己主动挂载和卸载的方法 mdev.conf
首先先參考这些博客做一些了解:http://linux.chinaunix.net/techdoc/install/2009/11/18/1144936.shtml http://www.cnblog ...
- Django创建数据表
Django中创建表. 用的django项目自带的sqlite数据库,创建完毕后将表注冊到jdango.admin,就能够在浏览器在管理了. 在django项目的models.py文件里: from ...
- apt-pkg
1 什么是apt-pkg python的apt库,可以做apt可以做的任何事情. 2 apt_pkg.parse_depends(depends, strip_multiarch=True) 这里的d ...