[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,多么痛的领悟...看来要恶补一下与期望相关的东西了. 这是 ...
随机推荐
- zmq.error.ZMQError: Address already in use
1.如下代码,启动的时候python app.py会报如题的错误 app.py #!/user/bin python # -*- coding:utf-8 -*- import os from dat ...
- Python遍历路径下文件并转换成UTF-8编码
http://www.cnblogs.com/wuyuegb2312/archive/2013/01/11/2856772.html 开始学Python,这篇文章来自于应用需求. os.walk很方便 ...
- 【APUE】fork函数
#include <unisth.h> pid_t fork(void) fork函数被调用一次,返回两次.子进程的返回值是0,父进程的返回值是子进程的进程id. fork函数调用一次却返 ...
- requests库帮助
requests库帮助 http://docs.python-requests.org/zh_CN/latest/user/quickstart.html
- Scala入门到精通——第二十四节 高级类型 (三)
作者:摆摆少年梦 视频地址:http://blog.csdn.net/wsscy2004/article/details/38440247 本节主要内容 Type Specialization Man ...
- Linux 将一般的用户加入sudo组is_not_in_the_sudoers_file._This_incident_will_be_reported解决方法
在一般用户下执行sudo命令提示xxx is not in the sudoers file. This incident will be reported.解决方法: $where ...
- C# Json反序列化 数据协定类型 无法反序列化 由于未找到必需的数据成员
背景今天在使用:C# Json 序列化与反序列化 反序列化的时候出现了以下的错误信息. System.Runtime.Serialization.SerializationException: 数据协 ...
- C++ 虚函数与纯虚函数 浅析
[摘要] 在虚函数与纯虚函数的学习中.要求理解虚函数与纯虚函数的定义,了解虚函数与纯虚函数在实例化上的差异.掌握两者在实现上的必要性.熟悉纯虚函数在子类与孙类的函数类型.本文即针对上述问题展开阐述. ...
- ios开发--NSDate与NSDateFormatter的相关用法【转】
原文地址:http://blog.sina.com.cn/s/blog_91ff71c0010188u9.html 1.NSDateFormatter配合NSDate与NSString之间的转化 N ...
- BindException 无法指定被请求的地址
Caused by: java.net.BindException: Problem binding to [hadoop3:8096] java.net.BindException: 无法指定被请求 ...