POJ 2096 Collecting Bugs (概率DP,求期望)
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
/*
POJ 2096
概率DP
dp求期望
逆着递推求解
题意:(题意看题目确实比较难道,n和s都要找半天才能找到)
一个软件有s个子系统,会产生n种bug
某人一天发现一个bug,这个bug属于一个子系统,属于一个分类
每个bug属于某个子系统的概率是1/s,属于某种分类的概率是1/n
问发现n种bug,每个子系统都发现bug的天数的期望。
求解:
dp[i][j]表示已经找到i种bug,j个系统的bug,达到目标状态的天数的期望
dp[n][s]=0;要求的答案是dp[0][0];
dp[i][j]可以转化成以下四种状态:
dp[i][j],发现一个bug属于已经有的i个分类和j个系统。概率为(i/n)*(j/s);
dp[i][j+1],发现一个bug属于已有的分类,不属于已有的系统.概率为 (i/n)*(1-j/s);
dp[i+1][j],发现一个bug属于已有的系统,不属于已有的分类,概率为 (1-i/n)*(j/s);
dp[i+1][j+1],发现一个bug不属于已有的系统,不属于已有的分类,概率为 (1-i/n)*(1-j/s);
整理便得到转移方程
*/
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
const int MAXN=;
double dp[MAXN][MAXN];
int main()
{
int n,s;
while(scanf("%d%d",&n,&s)!=EOF){
dp[n][s]=;
for(int i=n;i>=;i--)
for(int j=s;j>=;j--){
if(i==n&&j==s)continue;
dp[i][j]=(i*(s-j)*dp[i][j+]+(n-i)*j*dp[i+][j]+(n-i)*(s-j)*dp[i+][j+]+n*s)/(n*s-i*j);
}
printf("%.4lf\n",dp[][]);
}
return ;
}
POJ 2096 Collecting Bugs (概率DP,求期望)的更多相关文章
- Poj 2096 Collecting Bugs (概率DP求期望)
C - Collecting Bugs Time Limit:10000MS Memory Limit:64000KB 64bit IO Format:%I64d & %I64 ...
- poj 2096 Collecting Bugs (概率dp 天数期望)
题目链接 题意: 一个人受雇于某公司要找出某个软件的bugs和subcomponents,这个软件一共有n个bugs和s个subcomponents,每次他都能同时随机发现1个bug和1个subcom ...
- 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)
题意:给定 n 类bug,和 s 个子系统,每天可以找出一个bug,求找出 n 类型的bug,并且 s 个都至少有一个的期望是多少. 析:应该是一个很简单的概率DP,dp[i][j] 表示已经从 j ...
- poj 2096 Collecting Bugs 概率dp 入门经典 难度:1
Collecting Bugs Time Limit: 10000MS Memory Limit: 64000K Total Submissions: 2745 Accepted: 1345 ...
- poj 2096 Collecting Bugs - 概率与期望 - 动态规划
Ivan is fond of collecting. Unlike other people who collect post stamps, coins or other material stu ...
- HDU3853-LOOPS(概率DP求期望)
LOOPS Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others) Total Su ...
- poj 2096 Collecting Bugs(期望 dp 概率 推导 分类讨论)
Description Ivan is fond of collecting. Unlike other people who collect post stamps, coins or other ...
- POJ 2096 Collecting Bugs 期望dp
题目链接: http://poj.org/problem?id=2096 Collecting Bugs Time Limit: 10000MSMemory Limit: 64000K 问题描述 Iv ...
随机推荐
- C#后台异步消息队列实现
简介 基于生产者消费者模式,我们可以开发出线程安全的异步消息队列. 知识储备 什么是生产者消费者模式? 为了方便理解,我们暂时将它理解为垃圾的产生到结束的过程. 简单来说,多住户产生垃圾(生产者)将垃 ...
- Myeclipse maven项目转web项目
右键点击项目,选择project facets,或者在properties选择,点“Convert to faceted from...” 勾选java和Dynamic Web Module 选项 接 ...
- TChart-图表的滚动与翻译
界面代码: object Form1: TForm1 Left = Top = Width = Height = Caption = 'Form1' Color = clBtnFace Font.Ch ...
- Mac-MacOS降级(Mac系统降级,系统回退)
前言 最近把macOS更新到了 macOS Catalina,使用了一段时间后,结合自己的使用环境和体验,感觉 Catalina 不太好用,就想把系统回退到 macOS Mojave,但是平时几乎不用 ...
- Python中verbaim标签使用详解
verbatim标签:默认在"DTL"模板中是会去解析那些特殊字符串的,比如{% 和 %}以及{{等.如果你在某个代码片段中不想使用"DTL"的解析引擎,那么就 ...
- 为什么选择Spring Boot?
本文概述了各种Spring配置样式,并帮助你了解配置Spring应用程序的复杂性.抽丝剥茧 细说架构那些事——[优锐课] Spring是一个非常流行的基于Java的框架,用于构建Web和企业应用程序. ...
- IDEA 代码量统计(Statistic)
IDEA 代码量统计(Statistic) 1.1 前言 项目到了一定阶段,都会想要看看项目的代码量情况,这里主要使用插件Statistic进行代码统计查看. 1.2 安装插件步骤 找到插件市场入口并 ...
- postman设置变量
参数化 变量引用格式:{{username}} , 区别jmeter的 {username} 一.设置与引用环境变量 背景:在不同的环境下跑相同的测试,生产环境或测试环境 二.设置与引用全局变量 ...
- cf938D
题意简述:n个点m条边的无向图,有点权,有边权, 对于每一个点计算,d(i,j)表示点i到点j的最短路 题解:边权扩大二倍,建立源点,然后源点向每一个点x连接一条权值为a[x]的边,然后跑最短路即可 ...
- 企业应用开发的大趋势,65%的应用开发将通过低代码完成 ZT
全球知名的咨询公司Gartner于近日发表了最新版的<低代码开发平台魔力象限>,并在报告中指出,到2024年65%的应用开发工作都将通过低代码的方式完成.Gartner长期关注软件开发领域 ...