poj 2096 Collecting Bugs - 概率与期望 - 动态规划
Two companies, Macrosoft and Microhard are in tight competition. Microhard wants to decrease sales of one Macrosoft program. They hire Ivan to prove that the program in question is disgusting. However, Ivan has a complicated problem. This new program has s subcomponents, and finding bugs of all types in each subcomponent would take too long before the target could be reached. So Ivan and Microhard agreed to use a simpler criteria --- Ivan should find at least one bug in each subsystem and at least one bug of each category.
Macrosoft knows about these plans and it wants to estimate the time that is required for Ivan to call its program disgusting. It's important because the company releases a new version soon, so it can correct its plans and release it quicker. Nobody would be interested in Ivan's opinion about the reliability of the obsolete version.
A bug found in the program can be of any category with equal probability. Similarly, the bug can be found in any given subsystem with equal probability. Any particular bug cannot belong to two different categories or happen simultaneously in two different subsystems. The number of bugs in the program is almost infinite, so the probability of finding a new bug of some category in some subsystem does not reduce after finding any number of bugs of that category in that subsystem.
Find an average time (in days of Ivan's work) required to name the program disgusting.
Input
Output
Sample Input
1 2
Sample Output
3.0000
题目大意 有n台电脑,每台电脑都有s种bug,每天等概率在一台电脑中发现一个bug,问所有电脑中至少发现了1种bug,并且所有种bug都被发现期望下需要的天数。
用 dp[i][j] 表示在i台电脑中发现了bug,有j种bug被发现到最终状态期望要的天数。
讨论下面几种情况
1)下一次在新的一台电脑上发现了新的一种bug,由 f[i + ][j + ] 转移过来
2)下一次在新的一台电脑上没有发现新的一种bug,由 f[i + ][j] 转移过来
3)下一次没有在新的一台电脑上发现了新的一种bug,由 f[i][j + ] 转移过来
4)下一次没有在新的一台电脑上没有发现新的一种bug,由 f[i][j] 转移过来
因此列得方程
整理得到转移方程。
Code
/**
* poj
* Problem#2096
* Accepted
* Time: 157ms
* Memory: 8648k
*/
#include <iostream>
#include <cstdio>
using namespace std; int n, s;
double f[][]; inline void init() {
scanf("%d%d", &n, &s);
} inline void solve() {
int ns = n * s; f[n][s] = ;
for(int i = n; ~i; i--)
for(int j = s; ~j; j--)
if(i < n || j < s)
f[i][j] = (f[i + ][j] * (n - i) * j + f[i][j + ] * i * (s - j) + f[i + ][j + ] * (n - i) * (s - j) + ns) / (ns - i * j); printf("%.4lf", f[][]);
} int main() {
init();
solve();
return ;
}
poj 2096 Collecting Bugs - 概率与期望 - 动态规划的更多相关文章
- POJ 2096 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求期望)
C - Collecting Bugs Time Limit:10000MS Memory Limit:64000KB 64bit IO Format:%I64d & %I64 ...
- poj 2096 Collecting Bugs 概率dp 入门经典 难度:1
Collecting Bugs Time Limit: 10000MS Memory Limit: 64000K Total Submissions: 2745 Accepted: 1345 ...
- poj 2096 Collecting Bugs (概率dp 天数期望)
题目链接 题意: 一个人受雇于某公司要找出某个软件的bugs和subcomponents,这个软件一共有n个bugs和s个subcomponents,每次他都能同时随机发现1个bug和1个subcom ...
- POJ 2096 Collecting Bugs (概率DP)
题意:给定 n 类bug,和 s 个子系统,每天可以找出一个bug,求找出 n 类型的bug,并且 s 个都至少有一个的期望是多少. 析:应该是一个很简单的概率DP,dp[i][j] 表示已经从 j ...
- POJ 2096 Collecting Bugs 期望dp
题目链接: http://poj.org/problem?id=2096 Collecting Bugs Time Limit: 10000MSMemory Limit: 64000K 问题描述 Iv ...
- poj 2096 Collecting Bugs 【概率DP】【逆向递推求期望】
Collecting Bugs Time Limit: 10000MS Memory Limit: 64000K Total Submissions: 3523 Accepted: 1740 ...
- poj 2096 Collecting Bugs && ZOJ 3329 One Person Game && hdu 4035 Maze——期望DP
poj 2096 题目:http://poj.org/problem?id=2096 f[ i ][ j ] 表示收集了 i 个 n 的那个. j 个 s 的那个的期望步数. #include< ...
- POJ 2096 Collecting Bugs
Collecting Bugs Time Limit: 10000MS Memory Limit: 64000K Total Submissions: 1716 Accepted: 783 C ...
随机推荐
- Appium基础(三)对象抓取
一.启动Android模拟器 二.打开App应用,这里以计算器为例子 三.打开uiautomatorviewer.bat 这个文件在Android SDK-->Tool目录下 双击uiautom ...
- oracle 常用(一)
常用的6个分组函数: 注意点:where字句中不能使用组函数.要用到having函数. 但是从优化角度看,尽量使用where avg :平均值 sum:求和 ...
- WebSocket.之.基础入门-后端响应消息
WebSocket.之.基础入门-后端响应消息 在<WebSocket.之.基础入门-前端发送消息>的代码基础之上,进行添加代码.代码只改动了:TestSocket.java 和 inde ...
- React-Native组件之Text内文字垂直居中方案
style: { height: 100, textAlign: 'center', textAlignVertical: 'center', } 以上方法在Android上显示水平垂直居中, 但在I ...
- vue--监听属性完成大小写字母间的转换
监听属性 watch侦听属性的作用是侦听某属性值的变化,从而做相应的操作,侦听属性是一个对象,它的键是要监听的对象或者变量,值一般是函数,当你侦听的元素发生变化时,需要执行的函数,这个函数有两个形参, ...
- XML系列之--创建电文格式的XML(一)
关于XML,学校那会,老师在口中仅仅提及,自己也未曾深入接触过,仅是些将最基本XML文件内容显示在web定义的表格中之类的简单操作,如今项目中的收发电文涉及到复杂XML的操作.趁此契机好好回顾下XML ...
- mongodb查看操作记录方法以及用户添加删除权限修改密码
前一阵跑程序时发现一个问题,同事导出了部分数据,但是在merge回原库时竟然和原库的数据对不上,后来找了半天发现是原库数据少了. 找了很多资料发现很多人认为的操作日志和我想的不太一样...找了半条才发 ...
- 【JavaScript 6连载】一、关于对象(访问)
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- leaflet:调用arcgis切片地图服务
var mymap = L.map('mapid').setView([31.59, 120.29], 7); L.tileLayer('http://map.geoq.cn/ArcGIS/rest/ ...
- <转>jmeter(十三)常见问题及解决方法
本博客转载自:http://www.cnblogs.com/imyalost/category/846346.html 个人感觉不错,对jmeter讲解非常详细,担心以后找不到了,所以转发出来,留着慢 ...