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的更多相关文章

  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. Maven远程仓库的配置

    在很多情况下,默认的中央仓库无法满足项目的需求,可能项目需要的构件存在于另外一个远程仓库中,如JBoss Maven仓库.这时,可以在POM中配置该仓库,见代码如下: <!-- 远程仓库的配置 ...

  2. spider RPC高级特性

    多租户 spider原生支持多租户部署,spider报文头对外开放了机构号.系统号两个属性用于支持多租户场景下的路由. 多租户场景下的路由可以支持下述几种模式: n  系统号: n  系统号+服务号( ...

  3. H5——表单验证新特性,注册模态框!

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  4. FlashBuilder4安装SVN插件步骤

    1. 选择菜单 帮助–> 安装新软件 2. 在使用里键入地址:  http://subclipse.tigris.org/update_1.6.x并点击添加 在Subclipse栏里选择带有Re ...

  5. UI-初识君面之理论篇

    一个好的app不光要用好的功能,还要有好的界面,这样内外兼修才算得上是一个好的App.其实跟人一样,不能只刷帅,要有内涵(看清楚哦,内涵不是指闷骚).不知不觉在园子里已经晃了八年,来深也八年了,.NE ...

  6. Highchart插件简介和引入方式

    一.Highchart简介: Highcharts 是一个用纯 JavaScript 编写的一个图表库, 能够很简单便捷的在 Web 网站或是 Web 应用程序添加有交互性的图表. Highchart ...

  7. redis数据结构存储Linked List设计细节(redis的设计与实现笔记)

    redis里拥有一个灵活扩展且获取表头表尾复杂度为O(1)的双端列表,分为list和listNode2部分组成. list: typedef struct list {//链表 listNode *h ...

  8. Sql Server 2016新功能之 Row-Level Security

    Sql Server 2016 有一个新功能叫 Row-Level Security ,大概意思是行版本的安全策略(原来我是个英语渣_(:з」∠)_) 直接上例子.这个功能相当通过对表添加一个函数作为 ...

  9. 1.uniq去重命令讲解

    uniq命令: 常见参数: -c,--count *****      在每行旁边显示改行重复出现的次数 -d,--repeated        仅显示重复出现的行,2次或2次以上的行,默认的去重包 ...

  10. JS--实现简单轮播(一)

    <!DOCTYPE html><html><head> <title></title> <meta charset=utf-8> ...