思路

分类讨论,不妨先设$DP[i][j]$表示已经发现$i$种子系统中有$n$种$bug$无非只有四种情况

  • 发现的$bug$在旧的系统旧的分类,概率$p1$是$(i/s)*(j/n)$.
  • 发现的$bug$在旧的系统新的分类,概率$p2$是$(i/s)*((n-j)/n)$
  • 发现的$bug$在新的系统旧的分类,概率$p3$是$((s-i)/s)*(j/n)$
  • 发现的$bug$在新的系统新的分类,概率$p4$是$((s-i)/s)*((n-j)/n)$
  • 那么我们很自然的就得到了下面的转移方程

$$dp[i][j] = p1*dp[i][j]+p2*dp[i][j+1]+p3*dp[i+1][j]+p4*dp[i+1][j+1]$$

代码

#include <iostream>
#include <cstdio>
#include <cstring> const int maxn = 1010; using namespace std; int n, s;
double dp[maxn][maxn], p1, p2, p3, p4; int main() {
while (scanf("%d%d", &n, &s) == 2) {
memset(dp,0,sizeof(dp));
for(int i=n; i>=0; --i) {
for(int j=s; j>=0; --j) {
if(i==n&&j==s)continue;
p1=1.0*i/n*j/s;
p2=1.0*(n-i)/n*j/s;
p3=1.0*i/n*(s-j)/s;
p4=1.0*(n-i)/n*(s-j)/s;
dp[i][j]=(p2*dp[i+1][j]+p3*dp[i][j+1]+p4*dp[i+1][j+1]+1.0)/(1.0-p1);
}
}
printf("%.4f\n",dp[0][0]);
}
}

  

  

POJ P2096 Collecting Bugs的更多相关文章

  1. POJ 2096 Collecting Bugs 期望dp

    题目链接: http://poj.org/problem?id=2096 Collecting Bugs Time Limit: 10000MSMemory Limit: 64000K 问题描述 Iv ...

  2. POJ 2096 Collecting Bugs

    Collecting Bugs Time Limit: 10000MS   Memory Limit: 64000K Total Submissions: 1716   Accepted: 783 C ...

  3. poj 2096 Collecting Bugs 概率dp 入门经典 难度:1

    Collecting Bugs Time Limit: 10000MS   Memory Limit: 64000K Total Submissions: 2745   Accepted: 1345 ...

  4. Poj 2096 Collecting Bugs (概率DP求期望)

    C - Collecting Bugs Time Limit:10000MS     Memory Limit:64000KB     64bit IO Format:%I64d & %I64 ...

  5. poj 2096 Collecting Bugs 【概率DP】【逆向递推求期望】

    Collecting Bugs Time Limit: 10000MS   Memory Limit: 64000K Total Submissions: 3523   Accepted: 1740 ...

  6. poj 2096 Collecting Bugs - 概率与期望 - 动态规划

    Ivan is fond of collecting. Unlike other people who collect post stamps, coins or other material stu ...

  7. POJ 2096 Collecting Bugs (概率DP,求期望)

    Ivan is fond of collecting. Unlike other people who collect post stamps, coins or other material stu ...

  8. 【概率】poj 2096:Collecting Bugs

    Description Ivan is fond of collecting. Unlike other people who collect post stamps, coins or other ...

  9. poj 2096 Collecting Bugs(期望 dp 概率 推导 分类讨论)

    Description Ivan is fond of collecting. Unlike other people who collect post stamps, coins or other ...

随机推荐

  1. web metrics dashboard 数据分析工具 看板 从可视化发现问题 避免sql重复写 调高效率

    <?php$todo = array();$done = array();$h = array();$v = $all['v'];$l = count($v);#19700101 08for ( ...

  2. Bootstrap Dropdown 源码分析

    /* ======================================================================== * Bootstrap: dropdown.js ...

  3. cssTest

    html <!doctype html> <html> <head> <meta charset="utf-8"> <meta ...

  4. 电脑的系统盘只有10G了

    软件也是缓存多了,准备把一些让家人卸载,昨天开始布置培训任务就是有一个电报的程序,把流程说了下,从今天开始就会指导,错误点分析.

  5. [Codeforces 339D] Xenia and Bit Operations

    [题目链接] https://codeforces.com/problemset/problem/339/D [算法] 线段树模拟即可 时间复杂度 :O(MN) [代码] #include<bi ...

  6. JavaScript代码优化新工具UglifyJS

    jQuery 1.5 发布的时候 john resig 大神说所用的代码优化程序从Google Closure切换到UglifyJS,新工具的压缩效果非常令人满意. UglifyJS 是一个服务端no ...

  7. bzoj 2165: 大楼【Floyd+矩阵乘法+倍增+贪心】

    1<<i的结果需要是long long的话i是long long是没用的--要写成1ll<<i--我别是个傻子吧 虽然写的是二进制贪心,但是我觉得二分可能更好写吧(但是会慢) ...

  8. mysql 的索引hash和b+tree 区别

    索引hash相当于数组,键值对组合,对于id = 6或者status= 2这样条件查询,但是对于id>12等这样,用btree索引最好.

  9. Java多线程(八) synchronized 抛出异常锁自动解除

    当一个线程执行的代码出现异常时,其所持有的锁会自动释放 public class MyObject { private int i = 1; synchronized public void meth ...

  10. ROS-URDF仿真

    前言:URDF (标准化机器人描述格式),是一种用于描述机器人及其部分结构.关节.自由度等的XML格式文件. 一.首先做一个带有四个轮子的机器人底座. 1.1 新建urdf文件 在chapter4_t ...