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 ...
随机推荐
- table可拖拽改变宽度
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- PHP面向对象构造和析构函数
一.构造函数 用来生成对象的函数 <?php class Ren{ public $name; public $sex;//性别是人一出生就知道的,可以用构造函数来定义 /*public fun ...
- sql 查询每科的前三名
废话不多说,直接上脚本 CREATE TABLE [dbo].[Students]( ,) NOT NULL, ) NULL, ) NULL, [score] [int] NOT NULL, CONS ...
- SQL Server物化视图学习笔记
一. 基本知识 摘抄自http://www.cnblogs.com/kissdodog/p/3385161.html SQL Server索引 - 索引(物化)视图 <第九篇> 索引视 ...
- python多版本控制
1安装git # yum install git -y 2.安装python依赖 # yum -y install gcc make patch gdbm-devel openssl-devel sq ...
- 回声状态网络(ESN)基础教程
http://jlearning.cn/2017/05/29/ESN-basic-tutorial/ 最近在看回声状态网络(Echo State Network)的内容,注意到中文搜索引擎搜不到关于有 ...
- Maven的作用、用途、内涵、愿景
maven被许多人认为是一个构建工具.许多人最初是从熟悉ant而转到maven的,因此很自然地这样认为maven是一个构建工具.但是maven并不仅仅是一个构建工具,也不是ant的一个替代工具.mav ...
- 【Hbase学习之三】Hbase Java API
环境 虚拟机:VMware 10 Linux版本:CentOS-6.5-x86_64 客户端:Xshell4 FTP:Xftp4 jdk8 hadoop-2.6.5 hbase-0.98.12.1-h ...
- CBV源码解析
1.CBV(class based view) 首先定义一个视图函数,用类的方式定义: 举例: class LoginView(View): def get(self,request): return ...
- Git HEAD detached from XXX (git HEAD 游离) 解决办法
本文 Git 图片主要来自:图解 Git,非常感谢! 读完本文你将了解: 什么是 HEAD HEAD 游离状态的利与弊 具体解决操作 Thanks 什么是 HEAD Git 中的 HEAD 可以理解为 ...