【POJ】2096 Collecting Bugs(数学期望)
题目
传送门:QWQ
分析
数学期望
用$ dp[i][j] $表示发现了在$ j $个子系统里面发现了$ i $个bug到$ s $个子系统里面发现了$ n $个bug需要的期望天数。
$ dp[0][0] $就是答案。
然后分类一下,可以转移到$ dp[i][j] $无非就是$ dp[i+1][j+1] $ $ dp[i][j+1] $ $ dp[i+1][j] $ $ dp[i][j] $
各自分别算一下概率,比如从$ dp[i][j] $转移过来的话概率是$ \frac{i}{n} \times \frac{j}{s} $因为这天要刚好落在已经选择过的$ i $个bug和$ j $个子系统里。
其他的也差不多。
代码
由于日常include <bits/stdc++.h>所以poj的ce数量超级多。。。。。
// #include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
using namespace std;
const int maxn=;
double dp[maxn][maxn];
int main(){
double n,s; scanf("%lf%lf",&n,&s);
memset(dp,,sizeof(dp));
for(int i=n;i>=;i--)
for(int j=s;j>=;j--){
if(i==n&&j==s) continue;
double p1=i*j/n/s,p2=i*(s-j)/n/s,p3=(s-j)*(n-i)/n/s,p4=(n-i)*j/n/s;
dp[i][j]=(+p2*dp[i][j+]+p3*dp[i+][j+]+p4*dp[i+][j])/(-p1);
}
printf("%.5f\n",dp[][]);
return ;
}
【POJ】2096 Collecting Bugs(数学期望)的更多相关文章
- 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 题意: 有一个程序猿,他每天都会发现一个bug. bug共有n个种类.属于某一个种类的概率为1/n. 有s个子系统,每个bug属 ...
- POJ 2096 Collecting Bugs 期望dp
题目链接: http://poj.org/problem?id=2096 Collecting Bugs Time Limit: 10000MSMemory Limit: 64000K 问题描述 Iv ...
- 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 天数期望)
题目链接 题意: 一个人受雇于某公司要找出某个软件的bugs和subcomponents,这个软件一共有n个bugs和s个subcomponents,每次他都能同时随机发现1个bug和1个subcom ...
- 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 (概率DP求期望)
C - Collecting Bugs Time Limit:10000MS Memory Limit:64000KB 64bit IO Format:%I64d & %I64 ...
- poj 2096 Collecting Bugs 【概率DP】【逆向递推求期望】
Collecting Bugs Time Limit: 10000MS Memory Limit: 64000K Total Submissions: 3523 Accepted: 1740 ...
- POJ 2096 Collecting Bugs
Collecting Bugs Time Limit: 10000MS Memory Limit: 64000K Total Submissions: 1716 Accepted: 783 C ...
- poj 2096 Collecting Bugs 概率dp 入门经典 难度:1
Collecting Bugs Time Limit: 10000MS Memory Limit: 64000K Total Submissions: 2745 Accepted: 1345 ...
随机推荐
- python 获取5天前的日期
from datetime import date, timedelta dt = date.today() - timedelta() print('Current Date :',date.tod ...
- 【Python】使用Pytest集成Allure生成漂亮的图形测试报告
前言 大概两个月前写过一篇<[测试设计]使用jenkins 插件Allure生成漂亮的自动化测试报告>的博客,但是其实Allure首先是一个可以独立运行的测试报告生成框架,然后才有了Jen ...
- SpringBoot全局异常处理方式
每个项目全局异常处理非常重要, 今天在处理项目架构的时候添加了一个全局异常处理. 大概三种异常情况: 一:在进入Controller之前,譬如请求一个不存在的地址,404错误. 二:在执行@Reque ...
- Rails 5 Test Prescriptions 第9章 Testing-JavaScript: Integration Testing,❌挂一个问题webpacker::helper
使用Capybara进行JS的集成测试 谈论驱动 让测试通过 Webpack in Development Mode Js设计 是用户在网页上有好的体验的重要因素. 尽管如此,许多网页不测试JS. 部 ...
- Codeforces Round #415 (Div. 2)C
反正又是一个半小时没做出来... 先排序,然后求和,第i个和第j个,f(a)=a[j]-a[i]=a[i]*(2^(j-i-1))因为从j到i之间有j-i-1个数(存在或者不存在有两种情况) 又有a[ ...
- L200
Last week, I read a story about a 34-year-old British woman who is extremely afraid of metal forks.S ...
- 探究js正则匹配方法:match和exec
match是字符串方法,写法为:str.match(reg) exec是正则表达式方法,写法为:reg.exec(str) match和exec在匹配成功时返回的都是数组,在没有匹配上时返回的都是nu ...
- UML类图中的各种箭头代表的含义(转自:http://www.cnblogs.com/damsoft/archive/2016/10/24/5993602.html)
1.UML简介Unified Modeling Language (UML)又称统一建模语言或标准建模语言. 简单说就是以图形方式表现模型,根据不同模型进行分类,在UML 2.0中有13种图,以下是他 ...
- Yii Model
REFs 自动生成代码 创建第一个Yii应用 创建模型 Yii 用户登陆机制
- w3m使用小记
By francis_hao Mar 8,2017 w3m是一个基于文本的web浏览器和分页器,运行在unix和windows系统上. 可显示包含链接的超文本标记语言(HTML),显示效果如 ...