【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爬虫scrapy学习之篇二
继上篇<python之urllib2简单解析HTML页面>之后学习使用Python比较有名的爬虫scrapy.网上搜到两篇相应的文档,一篇是较早版本的中文文档Scrapy 0.24 文档, ...
- python 读取位于包中的数据文件
假设你的包中的文件组织成如下: mypackage/ __init__.py somedata.dat spam.py 现在假设spam.py文件需要读取somedata.dat文件中的内容.你可以用 ...
- JVM史上最佳入门指南
提到Java虚拟机(JVM),可能大部分人的第一印象是“难”,但当让我们真正走入“JVM世界”的时候,会发现其实问题并不像我们想象中的那么复杂.唯一真正令我们恐惧的,其实是恐惧本身.而作为整个JVM系 ...
- Android 各API版本代码常量
Android开发中常常有版本比较这个功能,来做版本兼容或者,其他相关效果等 以下是Android 7.0版本下的源码: public static class VERSION_CODES { ...
- poj3436网络流之最大流拆点
这题看了半天看不懂题意...还是看的网上题意写的 加一个源点一个汇点,把每个点拆成两个,这两个点的流量是v,其他联通的边都设为无穷大 输入没有1的点就与源点连接,输出只有1的点就与汇点连接 还有这个输 ...
- Vue.js图片预览插件
vue-picture-preview-extend vue-picture-preview的扩展版本,本文中插件是由其他大神开发,我做了一些扩展,原文链接:https://segmentfault. ...
- Oracle 9i & 10g编程艺术-深入数据库体系结构-学习笔记(持续更新中)
--20170322 --1.0 --更新表的统计信息begin dbms_stats.set_table_stats(user,'EMP',numrows => 10000);end; beg ...
- EPANET头文件解读系列6——HASH.H
该文件是EPANET中HASH.C的头文件,下面列出了该文件的源码以及我的中文注释 /* HASH.H**** Header file for Hash Table module HASH.C***/ ...
- POJ 3414 Pots 暴力,bfs 难度:1
http://poj.org/problem?id=3414 记录瓶子状态,广度优先搜索即可 #include <cstdio> #include <cstring> #inc ...
- hdu 3268 09 宁波 现场 I - Columbus’s bargain 读题 最短路 难度:1
Description On the evening of 3 August 1492, Christopher Columbus departed from Palos de la Frontera ...