思路

分类讨论,不妨先设$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. Binary safe

    https://en.wikipedia.org/wiki/Binary-safe A binary-safe function is one that treats its input as a r ...

  2. 玲珑学院OJ 1028 - Bob and Alice are playing numbers 字典树,dp

    http://www.ifrog.cc/acm/problem/1028 题解处:http://www.ifrog.cc/acm/solution/4 #include <cstdio> ...

  3. 【SCOI 2007】 降雨量

    [题目链接] 点击打开链接 [算法] 线段树 此题细节很多,写程序时要细心! [代码] #include<bits/stdc++.h> using namespace std; #defi ...

  4. bzoj1597 [Usaco2008 Mar]土地购买——斜率优化DP

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1597 就是斜率优化水题... 然而WA了十几遍,正负号处理真让人心累... 还是该负就负,别 ...

  5. mipi差分信号原理

    差分信号,什么是差分信号 一个差分信号是用一个数值来表示两个物理量之间的差异.从严格意义上来讲,所有电压信号都是差分的,因为一个电压只能是相对于另一个电压而言的.在某些系统里,系统’地’被用作电压基准 ...

  6. FreeMarker:什么是 FreeMarker?

    ylbtech-FreeMarker:什么是 FreeMarker? 1.返回顶部 1. FreeMarker 是一款 模板引擎: 即一种基于模板和要改变的数据, 并用来生成输出文本(HTML网页,电 ...

  7. 移动端html touch事件

    诸如智能手机和平板电脑一类的移动设备通常会有一(capacitive touch-sensitivescreen),以捕捉用户的手指所做的交互.随着移动网络的发展,其能够支持越来越复杂的应用,web开 ...

  8. C++中虚析构函数的作用 (转载)

    转自:http://blog.csdn.net/starlee/article/details/619827 我们知道,用C++开发的时候,用来做基类的类的析构函数一般都是虚函数.可是,为什么要这样做 ...

  9. E20171102-E

    segment   n. 环节; 部分,段落; [计算机] (字符等的) 分段; [动物学] 节片; distinct  adj. 明显的,清楚的; 卓越的,不寻常的; 有区别的; 确切的;

  10. [App Store Connect帮助]六、测试 Beta 版本(1)TestFlight Beta 版测试概述(iOS、Apple TVOS、watchOS)

    TestFlight Beta 版测试让您可以分发您 App 的 Beta 版构建版本给测试员并收集反馈.您可以在您的 App Store Connect 帐户中一次为至多 100 个 App 启用 ...