【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 ...
随机推荐
- Learning Ansible with Vagrant
介绍 Vagrant介绍 Vagrant是一款构建虚拟开发环境的工具,Vagrant的使用依赖于VirtualBox,VMware等一些虚拟机,通过Vagrant能更加方便的管理虚拟机,同时还能够通过 ...
- Minimum Depth of Binary Tree,求树的最小深度
算法分析:递归和非递归两种方法. public class MinimumDepthofBinaryTree { //递归,树的最小深度,就是它左右子树的最小深度的最小值+1 public int m ...
- codevs 1690 开关灯 线段树+延迟标记
1690 开关灯 时间限制: 1 s 空间限制: 128000 KB 题目描述 Description YYX家门前的街上有N(2<=N<=100000)盏路灯,在晚上六点之前,这 ...
- [POI2012]ROZ-Fibonacci Representation (数学)
大意:给定n, 求至少要多少个斐波那契数相加减后能得到n (可以重复, 重复的算多次) 假设$dp(x)$为$x$的最小划分, 有$dp(x)=dp(x-F_k)+1$, 其中$F_k$为最接近$x ...
- 解决ubuntu登陆失败,"Failed to start session"的问题
我是在虚拟机中安装了Ubuntu 14.04 系统,在Ubuntu 中执行 apt-get update 和 apt-get upgrade 命令后,然后重启系统. 但是,在重启成功后,在登 ...
- linux 命令 --while
shell while 语法: while [条件判断式] do 程序 done 对 while 循环来讲,只要条件判断式成立,循环就会一直进行,直到条件判断式不成立,循环才会停止. 例如: 循环从1 ...
- ISE创建Microblaze软核(三)
第七步 进入SDK开发环境 编译完成后弹出如下对话框,选择SDK的工作目录.在MicroblazeTutor中创建一个Workspace文件夹,并选择该文件夹为SDK的工作目录. 进入SDK主界面. ...
- iOS UILabel两端对齐的实现(可包括中英文/数字)
- (void)conversionCharacterInterval:(NSInteger)maxInteger current:(NSString *)currentString withLabe ...
- BigDecimal 、BigInteger
package com.BigDecimal; public class BigDecimalDemo { /* * 下面的运算的结果出乎我们的意料,有些准确,有些不准确 * 这是为什么呢? * 我们 ...
- cn_office_Professional_Plus_2010_vol_with_sp2-【x86+x64仅2.45GB】
用官方sp2补丁在cn_office_Professional_Plus_2010_vol基础上集成,无其他任何添加及修改! 文件: cn_office_Professional_Plus_2010_ ...