思路

分类讨论,不妨先设$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. http trigger 事件源是事件的生产者,函数是事件的处理者

    以函数计算作为 API 网关后端服务_用户指南(开放 API)_API 网关-阿里云  https://help.aliyun.com/document_detail/54788.html 创建触发器 ...

  2. Grunt学习日记

    Grunt和 Grunt 插件是通过npm安装并管理的, npm是Node.js的包管理器. 第一步:先安装node.js环境 第二步:安装Grunt-CLI 在node.js命令工具中输入npm i ...

  3. 【BZOJ 5165】 树上倍增

    [题目链接] 点击打开链接 [算法] 树上倍增,时间复杂度 : O(qklog(n)) [代码] #include<bits/stdc++.h> using namespace std; ...

  4. 【HDU 1588】 Gauss Fibonacci

    [题目链接] 点击打开链接 [算法] 要求 f(g(0)) + f(g(1)) + f(g(2)) + ... + f(g(n-1)) 因为g(i) = k * i + b 所以原式 = f(b) + ...

  5. windows 下操作目录(使用DOS命令)

    Attrib 更改单个文件或目录的属性.该命令设置或删除指派给文件或目录的只读.系统.存档.隐藏以及压缩属性. 含有下列参数的 attrib 命令仅当使用故障恢复控制台时才可用.含有不同参数的 att ...

  6. 利用 BASE64Encoder 对字符串进行加密 BASE64Decoder进行解密

    转自:https://blog.csdn.net/chenyongtu110/article/details/51694323

  7. ODP.NET Managed 相关文章收集

      一.Oracle 对.net支持的一些基础知识了解介绍. 1.早年的时候,微软自己做的有 System.Data.OracleClient. 现在已经成了过期类了.性能等都不是很好. 2.Orac ...

  8. linux守护进程的编写

    linux监控一个进程进行 代码如下: #!/bin/sh cd /home/autoprocess/ auto=`pgrep -f autoProcessNew.php | wc -l` if [ ...

  9. $CF1153A\ Serval\ and\ Bus$

    看大佬的代码都好复杂(不愧是大佬\(orz\) 蒟蒻提供一种思路 因为求的是最近的车对吧\(qwq\) 所以我们可以用一个\(while\)循环所以没必要去用什么 \(for...\) 至于这是\(d ...

  10. 64位linux安装wine等软件

    我的系统是centos7 64位的,安装wine的时候以为和32位的一样,结果执行./configure的时候,出现错误(无法建立一个32位程序,您需要安装32位的开发库) configure: er ...