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 ...
随机推荐
- cocos2d-x C++ (iOS)集成第三方微信分享
1.新建项目并下载 ShareSDK 1.Cocos2d-x项目环境搭建,不会的童鞋自行面壁哈: 网页链接. 2.ShareSDK iOS版本的 Cocos2d-x 插件是在ShareSDK iOS版 ...
- django 【form表单】
#########################根据类来生成表单################# ''' django form类 通模型类的属性映射到数据库的字段一样,表单类的字段会映射到HTM ...
- UML学习笔记(五)--顺序图
顺序图是用来描述对象自身及对象间信息传递顺序的视图.它用来表示用例中的行为顺序.当执行一个用例行为时,顺序图中的每条消息对应了一个类操作或状态机中引起转换的触发事件.它着重显示了参与相互作用的对象和所 ...
- Nginx查看并发链接数
一.通过界面查看通过web界面查看时Nginx需要开启status模块,也就是安装Nginx时加上 --with-http_stub_status_module 一.通过界面查看 通过web界面查看时 ...
- EL语言表达式 (一)【语法和特点】
一.基本语法规则: EL表达式语言以“${”开头,以"}"结尾的程序段,具体格式如下: ${expression} 其中expression:表示要指定输出的内容和字符串以及EL运 ...
- AngularJs ng-change事件/指令(转)
from:http://blog.csdn.net/u011127019/article/details/52564111 定义和用法 ng-change 指令用于告诉 AngularJS 在 HTM ...
- scrapy 参考教程及安装
scrapy 参考教程及安装环境: win7/10 64bit, python 3.6.x教程: http://python.jobbole.com/86405/安装过程0. 预先安装 VC14 64 ...
- 5.JVM的内存区域划分
一.JVM介绍 1. 什么是JVM? JVM是Java Virtual Machine(Java虚拟机)的缩写,JVM是一种用于计算设备的规范,它是一个虚构出来的计算机,是通过在实际的计算机上仿真模拟 ...
- fzu2204 dp
2015-10-06 19:31:05 n个有标号的球围成一个圈.每个球有两种颜色可以选择黑或白染色.问有多少种方案使得没有出现连续白球7个或连续黑球7个. 每组包含n,表示球的个数.(1 <= ...
- jQuery工具--$.each()和$.merge()
jQuery.each(object, [callback])或者jQuery(object).each([callback]) 概述 通用遍历方法,可用于遍历对象和数组. 不同于遍历 jQue ...