【poj2096】 Collecting Bugs
http://poj.org/problem?id=2096 (题目链接)
题意
有一个程序,其中有s个子结构,每个子结构出bug的概率相等。bug总共分成n类,每种bug出现的概率相等。每天找出一个bug,求所有子结构都出现bug并且每种bug都出现过所需要的期望天数。
Solution
终于领会了期望dp的一点点。。。
细节
%.4lf用G++交会Wa。。
代码
// poj2096 #include<algorithm> #include<iostream> #include<cstdlib> #include<cstring> #include<cstdio> #include<cmath> #include<queue> #define LL long long #define inf 1<<30 #define Pi acos(-1.0) #define free(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout); using namespace std; const int maxn=1010; double f[maxn][maxn]; int n,m; int main() { scanf("%d%d",&n,&m); f[n][m]=0; for (int i=n;i>=0;i--) for (int j=m;j>=0;j--) { if (i+1<=n) f[i][j]+=f[i+1][j]*(1-(double)i/n)*(double)j/m; if (j+1<=m) f[i][j]+=f[i][j+1]*(1-(double)j/m)*(double)i/n; if (i+1<=n && j+1<=m) f[i][j]+=f[i+1][j+1]*(1-(double)i/n)*(1-(double)j/m); if (i!=n || j!=m) f[i][j]=(f[i][j]+1)/(1-(double)i/n*(double)j/m); } printf("%.4lf",f[0][0]); return 0; }
【poj2096】 Collecting Bugs的更多相关文章
- 【POJ2096】Collecting Bugs 期望
[POJ2096]Collecting Bugs Description Ivan is fond of collecting. Unlike other people who collect pos ...
- 【poj2096】Collecting Bugs
题目描述 Ivan is fond of collecting. Unlike other people who collect post stamps, coins or other materia ...
- 【poj2096】Collecting Bugs 期望dp
题目描述 Ivan is fond of collecting. Unlike other people who collect post stamps, coins or other materia ...
- 【POJ】【2096】Collecting Bugs
概率DP/数学期望 kuangbin总结中的第二题 大概题意:有n个子系统,s种bug,每次找出一个bug,这个bug属于第 i 个子系统的概率为1/n,是第 j 种bug的概率是1/s,问在每个子系 ...
- 【POJ 2096】 Collecting Bugs
[题目链接] http://poj.org/problem?id=2096 [算法] 概率DP [代码] #include <algorithm> #include <bitset& ...
- 【POJ 2096】Collecting Bugs 概率期望dp
题意 有s个系统,n种bug,小明每天找出一个bug,可能是任意一个系统的,可能是任意一种bug,即是某一系统的bug概率是1/s,是某一种bug概率是1/n. 求他找到s个系统的bug,n种bug, ...
- 【分享】Collecting all the cheat sheets
http://overapi.com/ 这个网站可以查询到所有与编程相关的各种技术,并给出详细的知识点(干货).
- poj 2096 Collecting Bugs 【概率DP】【逆向递推求期望】
Collecting Bugs Time Limit: 10000MS Memory Limit: 64000K Total Submissions: 3523 Accepted: 1740 ...
- poj2096 Collecting Bugs(概率dp)
Collecting Bugs Time Limit: 10000MS Memory Limit: 64000K Total Submissions: 1792 Accepted: 832 C ...
随机推荐
- IntelliJ IDEA使用(二):tomcat和jetty配置
上一讲用idea创建了maven web项目,接下来我们把项目发布到tomcat和jetty运行,以便进一步地开发和调试 配置tomcat 第一.打开菜单栏 第二.点击设置按钮,添加应用服务器,选择t ...
- 深入浅出node(2) 模块机制
这部分主要总结深入浅出Node.js的第二章 一)CommonJs 1.1CommonJs模块定义 二)Node的模块实现 2.1模块分类 2.2 路径分析和文件定位 2.2.1 路径分析 2.2.2 ...
- css3深入了解之奇技淫巧
前言 自CSS3流行以来,虽然以前看过一遍所有的新增属性,但其实在实际项目中用到的少之又少.所以没有形成系统性的认识,以及看到效果立马就能想到解决方案的能力.然后最近正好遇到一个需要绘制大量动画的需求 ...
- VS2012 Unit Test 个人学习汇总(含目录)
首先,给出MSDN相关地址:http://msdn.microsoft.com/en-us/library/Microsoft.VisualStudio.TestTools.UnitTesting.a ...
- Retrofit结合RxJava使用指南
Retrofit结合RxJava使用指南 Retrofit是一个当前很流行的网络请求库, 官网的介绍是: "Type-safe HTTP client for Android and Jav ...
- 如何理解javaScript对象?
在我们生活中,常常会提到对象一词,如:你找到对象了吗?你的对象是谁呀?等等. 在我们家庭中,有男友的女青年都会说我有对象了,那么她的对象是XX(她的男友). 夫妻间呢?都会说我的爱人是谁谁谁,现在我们 ...
- Eclipse创建Maven工程报错
问题 用Eclipse创建maven工程的时候,总是会报错,例如提示: Unable to create project from archetype [org.apache.maven.archet ...
- vim 中替换
将80替换为10.0.0.19:80 :g/80/s//10.0.0.19:80/g
- Linux设备树语法详解
概念 Linux内核从3.x开始引入设备树的概念,用于实现驱动代码与设备信息相分离.在设备树出现以前,所有关于设备的具体信息都要写在驱动里,一旦外围设备变化,驱动代码就要重写.引入了设备树之后,驱动代 ...
- APUE学习之多线程编程(三):线程属性、同步属性
一.线程属性 可以使用pthread_attr_t结构修改线程默认属性,并这些属性和创建的线程练习起来,可以使用pthread_att_init函数初始化pthread_attr_t结构,调 ...