http://poj.org/problem?id=2096 (题目链接)

题意

  有一个程序,其中有s个子结构,每个子结构出bug的概率相等。bug总共分成n类,每种bug出现的概率相等。每天找出一个bug,求所有子结构都出现bug并且每种bug都出现过所需要的期望天数。

Solution

  终于领会了期望dp的一点点。。。

细节

  %.4lf用G++交会Wa。。

代码

  1. // poj2096
  2. #include<algorithm>
  3. #include<iostream>
  4. #include<cstdlib>
  5. #include<cstring>
  6. #include<cstdio>
  7. #include<cmath>
  8. #include<queue>
  9. #define LL long long
  10. #define inf 1<<30
  11. #define Pi acos(-1.0)
  12. #define free(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout);
  13. using namespace std;
  14.  
  15. const int maxn=1010;
  16. double f[maxn][maxn];
  17. int n,m;
  18.  
  19. int main() {
  20. scanf("%d%d",&n,&m);
  21. f[n][m]=0;
  22. for (int i=n;i>=0;i--)
  23. for (int j=m;j>=0;j--) {
  24. if (i+1<=n) f[i][j]+=f[i+1][j]*(1-(double)i/n)*(double)j/m;
  25. if (j+1<=m) f[i][j]+=f[i][j+1]*(1-(double)j/m)*(double)i/n;
  26. if (i+1<=n && j+1<=m) f[i][j]+=f[i+1][j+1]*(1-(double)i/n)*(1-(double)j/m);
  27. if (i!=n || j!=m) f[i][j]=(f[i][j]+1)/(1-(double)i/n*(double)j/m);
  28. }
  29. printf("%.4lf",f[0][0]);
  30. return 0;
  31. }

【poj2096】 Collecting Bugs的更多相关文章

  1. 【POJ2096】Collecting Bugs 期望

    [POJ2096]Collecting Bugs Description Ivan is fond of collecting. Unlike other people who collect pos ...

  2. 【poj2096】Collecting Bugs

    题目描述 Ivan is fond of collecting. Unlike other people who collect post stamps, coins or other materia ...

  3. 【poj2096】Collecting Bugs 期望dp

    题目描述 Ivan is fond of collecting. Unlike other people who collect post stamps, coins or other materia ...

  4. 【POJ】【2096】Collecting Bugs

    概率DP/数学期望 kuangbin总结中的第二题 大概题意:有n个子系统,s种bug,每次找出一个bug,这个bug属于第 i 个子系统的概率为1/n,是第 j 种bug的概率是1/s,问在每个子系 ...

  5. 【POJ 2096】 Collecting Bugs

    [题目链接] http://poj.org/problem?id=2096 [算法] 概率DP [代码] #include <algorithm> #include <bitset& ...

  6. 【POJ 2096】Collecting Bugs 概率期望dp

    题意 有s个系统,n种bug,小明每天找出一个bug,可能是任意一个系统的,可能是任意一种bug,即是某一系统的bug概率是1/s,是某一种bug概率是1/n. 求他找到s个系统的bug,n种bug, ...

  7. 【分享】Collecting all the cheat sheets

    http://overapi.com/   这个网站可以查询到所有与编程相关的各种技术,并给出详细的知识点(干货).

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

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

  9. poj2096 Collecting Bugs(概率dp)

    Collecting Bugs Time Limit: 10000MS   Memory Limit: 64000K Total Submissions: 1792   Accepted: 832 C ...

随机推荐

  1. String 中去掉空格

    JAVA中去掉空格 1. String.trim() trim()是去掉首尾空格 2.str.replace(" ", ""); 去掉所有空格,包括首尾.中间 ...

  2. About 静态代码块,普通代码块,同步代码块,构造代码块和构造函数的纳闷

    构造函数用于给对象进行初始化,是给与之对应的对象进行初始化,它具有针对性,函数中的一种.特点:1:该函数的名称和所在类的名称相同.2:不需要定义返回值类型.3:该函数没有具体的返回值.记住:所有对象创 ...

  3. ipython notebook 浏览器中编写数学公式和现实

    Python Notebook简介1 http://www.cnblogs.com/cbscan/p/3545084.html $ python -m IPython http://pypi.pyth ...

  4. Android Weekly Notes Issue #219

    Android Weekly Issue #219 August 21st, 2016 Android Weekly Issue #219 ARTICLES & TUTORIALS Andro ...

  5. 用NSAttributedString实现简单的图文混排

    iOS7以后,因为TextKit的强大,可以用NSAttributedString很方便的实现图文混排(主要是利用了NSTextAttachment). 关于Textkit的牛逼之处,可以参考objc ...

  6. Android设置图片内存溢出(OOM)问题——Android开发进阶之路6

    ImageView设置图片必备常识技术: Android设备会给每个应用分配16M的内存空间,如果你设置的图片的比较大且同一个页面有多个时,经常会报OOM错误导致程序奔溃.所以在这种情况下我们必须要对 ...

  7. git与github安装、配置、pull、push

    操作系统是Ubuntu 16.04 LTS 64bit 1 安装git (1)安装 sudo apt-get install git-core (2)一些全局变量的初始化 在本地建立一个文件夹,然后做 ...

  8. Oracle计算两个时间戳相差秒数,精确到毫秒

    with t as (select to_timestamp('2015-01-01 11:13:15.023456', 'yyyy-mm-dd hh24:mi:ss.ff9') t1, to_tim ...

  9. java、easyui-combotree树形下拉选择框

    最近一直在研究这个树形的下拉选择框,感觉非常的有用,现在整理下来供大家使用: 首先数据库的表架构设计和三级菜单联动的表结构是一样,(父子关系) 1.下面我们用hibernate建一下对应的额实体类: ...

  10. 【msql】关于redo 和 undo log

    InnoDB 有两块非常重要的日志,一个是undo log,另外一个是redo log,前者用来保证事务的原子性以及InnoDB的MVCC,后者用来保证事务的持久性.和大多数关系型数据库一样,Inno ...