题目大意:有n种bug,m个程序,小明每天能找到一个bug。每次bug出现的种类和所在程序都是等机会均等的,并且默认为bug的数目无限多。如果要使每种bug都至少找到一个并且每个程序中都至少找到一个bug,小明平均需要找几天?

题目分析:定义状态dp(i,j)表示找到了 i 种程序,并且出现在了 j 个程序中还需要的平均时间。则状态转移方程为:

dp(i,j)=i/n*j/m*dp(i,j)+(n-i)/n*j/m*dp(i+1,j)+i/n*(m-j)/m*dp(i,j+1)+(n-i)/n*(m-j)/m*dp(i+1,j+1)+1。

逆推之。

ps:这道题的题意不好懂。。

代码如下:

# include<iostream>
# include<cstdio>
# include<cstring>
# include<algorithm>
using namespace std; int n,m;
double dp[1005][1005]; int main()
{
while(~scanf("%d%d",&n,&m))
{
memset(dp,0,sizeof(dp));
for(int i=n;i>=0;--i){
for(int j=m;j>=0;--j){
if(i==n&&j==m) continue;
double right=(double(m-j)*i)/n/m;
double low=(double(n-i)*j)/n/m;
double rl=(double(n-i)*(m-j))/n/m;
double th=1.0-((double)(i*j))/n/m;;
dp[i][j]=right*dp[i][j+1]+low*dp[i+1][j]+rl*dp[i+1][j+1]+1;
dp[i][j]/=th;
}
}
printf("%.4lf\n",dp[0][0]);
}
return 0;
}

  

POJ-2096 Collecting Bugs (概率DP求期望)的更多相关文章

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

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

  2. poj 2096 Collecting Bugs (概率dp 天数期望)

    题目链接 题意: 一个人受雇于某公司要找出某个软件的bugs和subcomponents,这个软件一共有n个bugs和s个subcomponents,每次他都能同时随机发现1个bug和1个subcom ...

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

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

  4. POJ2096 Collecting Bugs(概率DP,求期望)

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

  5. POJ 2096 Collecting Bugs (概率DP)

    题意:给定 n 类bug,和 s 个子系统,每天可以找出一个bug,求找出 n 类型的bug,并且 s 个都至少有一个的期望是多少. 析:应该是一个很简单的概率DP,dp[i][j] 表示已经从 j ...

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

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

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

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

  8. HDU3853-LOOPS(概率DP求期望)

    LOOPS Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others) Total Su ...

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

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

  10. POJ 2096 Collecting Bugs 期望dp

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

随机推荐

  1. iperf3.0 hisi uclib 交叉编译

    1. 下载iperf src https://github.com/esnet/iperf/ 2.修改makefile.in 里面的配置. src/Makefile.in 613行 地方两行,去掉-p ...

  2. JDBC批量插入数据优化,使用addBatch和executeBatch

    JDBC批量插入数据优化,使用addBatch和executeBatch SQL的批量插入的问题,如果来个for循环,执行上万次,肯定会很慢,那么,如何去优化呢? 解决方案:用 preparedSta ...

  3. django 加载静态文件(图片,js,css)

    昨天写过一个项目通过django上传展示图片,但是今天写项目的时候发现出现了问题,静态文件加载不出来了,尴尬的一笔~ 记录一下静态文件的使用方法,基础~ ----------------------- ...

  4. 20145118 《Java程序设计》课程总结

    20145118 <Java程序设计>课程总结 每周读书笔记连接汇总 假期笔记 http://www.cnblogs.com/cy1123/p/5224305.html 第一周读书笔记 h ...

  5. 20145220韩旭飞《网络对抗》Exp8 Web基础

    20145220韩旭飞<网络对抗>Exp8 Web基础 Web前端:HTML基础 首先,我们的Web开发是基于Apache服务器进行的,所以对于Apache的基本操作我们是应该要掌握的,对 ...

  6. 20145305 《网络对抗》Web安全基础实践

    实践过程及结果截图 Phishing with XSS 在文本框里面写一个钓鱼网站代码就可以了 </form> <script> function hack(){ XSSIma ...

  7. python中command执行shell命令脚本方法

    在Python中有一个模块commands也很容易做到以上的效果.看一下三个函数:1). commands.getstatusoutput(cmd)用os.popen()执行命令cmd, 然后返回两个 ...

  8. C# MD5一句话加密

    System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5")

  9. word2vec 中的数学原理详解(一)目录和前言【转】

    本文转载自:https://blog.csdn.net/itplus/article/details/37969519 word2vec 是 Google 于 2013 年开源推出的一个用于获取 wo ...

  10. vim 操作快捷键 待更~

    shift + g 文件尾 ------ gdb p print start 从main函数开始 n next换行 s step 进入函数