思路

分类讨论,不妨先设$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. 【OI】简单的分块

    介绍下简单的分块: 当我们遇到区间类问题的时候,如何保证我们快速而高效地完成操作? 答案是线段树分块. 所谓分块,就是把一个序列分成许多块分别维护.是不是想起了树状数组 这样能大大提高效率: 例如,我 ...

  2. ios29--多线程

    进程是指在系统中正在运行的一个应用程序(一个程序可以对应多个进程).每个进程之间是独立的,每个进程均运行在其专用且受保护的内存空间内.比如同时打开迅雷.Xcode,系统就会分别启动2个进程.1个进程要 ...

  3. 英式英语 vs 美式英语

    0. 常见不同 日期的表达: 美国:月日年: 英国:日月年: 1. 发音 schedule,美 ['skɛdʒul],英 [ˈʃɛdjuːl] pecan,山核桃,英 ['piːk(ə)n;],美 [ ...

  4. nodejs常用命令

    npm是一个node包管理和分发工具,已经成为了非官方的发布node模块(包)的标准.有了npm,可以很快的找到特定服务要使用的包,进行下载.安装以及管理已经安装的包. 1.npm install m ...

  5. ubuntu/linuxmint更换163源及常用软件PPA源记录

    一.163源使用说明 (具体见:http://mirrors.163.com/,不推荐linuxmint更换源!!!) 以Wily(15.10)为例, 编辑/etc/apt/sources.list文 ...

  6. Shell脚本下条件测试(eq.ne.....)(转载)

    转载:http://cxj632840815.blog.51cto.com/3511863/1168709 Shell编程中的条件测试 在Linux编程中经常会用到判断数值的大小,字符串是否为空这样或 ...

  7. [App Store Connect帮助]六、测试 Beta 版本(4.4) 管理 Beta 版构建版本:停止测试构建版本

    在首页上,点按“我的 App”,选择您的 App,然后在工具栏中点按“TestFlight”. 在左列中的“构建版本”下,点按您 App 的平台(iOS 或 Apple TVOS). 在右表中,点按该 ...

  8. 基于Hexo且在GitHub上搭建博客

    title: 基于Hexo且在GitHub上搭建博客 Welcome to Fofade's Blog! 搭建初衷 大大小小,大学两年,玩了很多,也学了很多. 回首望之,曾经不知道的,现在是知道了,但 ...

  9. hadoop2.x 常用端口及定义方法

    一 常用端口号 1 HDFS 2 YARN 3 HBase 4 Hive 5 ZooKeeper 二 Web UIHTTP服务 1 对于存在 Web UIHTTP服务的所有 hadoop daemon ...

  10. [Qt Creator 快速入门] 第5章 应用程序主窗口

    对于日常见到的应用程序而言,许多都是基于主窗口的,主窗口中包含了菜单栏.工具栏.状态栏和中心区域等.这一章会详细介绍主窗口的每一个部分,还会涉及资源管理.富文本处理.拖放操作和文档打印等相关内容.重点 ...