poj-2096-期望/dp
http://poj.org/problem?id=2096
有n种病毒,s个服务器,每天等概率的在某个服务器上发现某一种病毒,问发现所有种类病毒且覆盖所有的服务器的期望天数。
利用全期望公式可以将期望分解为子期望的加权和,权值就是子期望发生的概率Pi,注意SUM{ Pi }=1;
假如我们已经完成了(i,j),目标是(n,s),那么下一天可能是(i,j) ,(i+1,j) ,(i,j+1) ,(i+1,j+1) 对应的Pi分别是 p1=(i/n)*(j/s) p2=(1-i/n)*(j/s) p3=(i/n)*(1-j/s) p4=(1-i/n)*(1-j/s)
设f(i,j)为完成了(i,j)距离目标的期望,那么有f(i,j)=p1*(f(i,j)+1)+p2*(f(i+1,j)+1)+p3*(f(i,j+1)+1)+p4*(f(i+1,j+1)+1) | f(n,s)=0 ,移项解出f(i,j)即可。
#include<iostream>
#include<cstring>
#include<queue>
#include<cstdio>
#include<stack>
#include<set>
#include<map>
#include<cmath>
#include<ctime>
#include<time.h>
#include<algorithm>
using namespace std;
#define mp make_pair
#define pb push_back
#define debug puts("debug")
#define LL long long
#define pii pair<int,int>
#define eps 1e-12 double f[][];
int main()
{
int n,m,i,j,k,t;
cin>>n>>m;
for(i=n;i>=;--i){
for(j=m;j>=;--j){
if(i==n&&j==m) continue;
double p1=(double)i*j,p2=(double)j*(n-i),
p3=(double)i*(m-j),p4=(double)(n-i)*(m-j);
p1/=(1.0*n*m);p2/=(1.0*n*m);p3/=(1.0*n*m);p4/=(1.0*n*m);
f[i][j]=p1+p2*(f[i+][j]+)+p3*(f[i][j+]+)+
p4*(f[i+][j+]+);
f[i][j]/=(1.0-p1);
}
}
printf("%.4f\n",f[][]);
return ;
}
poj-2096-期望/dp的更多相关文章
- poj - 2096 概率dp (找bug)
题意:一个人一天只能找1个bug ,这个bug属于s个子系统中的某一个子系统,属于n种bug 中的某一种 ,求 这个人找出n种bug ,并且s个系统都bug的期望 (每个系统的一定可以找出bug) 一 ...
- POJ 2096 (概率DP)
题目链接: http://poj.org/problem?id=2096 题目大意:n种bug,s个子系统.每天随机找一个bug,种类随机,来自系统随机.问找齐n种bug,且每个子系统至少有一个bug ...
- POJ 2096 Collecting Bugs (概率DP,求期望)
Ivan is fond of collecting. Unlike other people who collect post stamps, coins or other material stu ...
- poj 2096 Collecting Bugs && ZOJ 3329 One Person Game && hdu 4035 Maze——期望DP
poj 2096 题目:http://poj.org/problem?id=2096 f[ i ][ j ] 表示收集了 i 个 n 的那个. j 个 s 的那个的期望步数. #include< ...
- poj 2096 , zoj 3329 , hdu 4035 —— 期望DP
题目:http://poj.org/problem?id=2096 题目好长...意思就是每次出现 x 和 y,问期望几次 x 集齐 n 种,y 集齐 s 种: 所以设 f[i][j] 表示已经有几种 ...
- POJ 2096 Collecting Bugs:期望dp
题目链接:http://poj.org/problem?id=2096 题意: 有一个程序猿,他每天都会发现一个bug. bug共有n个种类.属于某一个种类的概率为1/n. 有s个子系统,每个bug属 ...
- POJ 2096 【期望DP】
题意: 有n种选择,每种选择对应m种状态.每种选择发生的概率相等,每种选择中对应的每种状态发生的概率相等. 求n种选择和m种状态中每种至少发生一次的期望. 期望DP好别扭啊.要用倒推的方法. dp[i ...
- poj 2096 Collecting Bugs(期望 dp 概率 推导 分类讨论)
Description Ivan is fond of collecting. Unlike other people who collect post stamps, coins or other ...
- POJ 2096 找bug 期望dp
题目大意: 一个人受雇于某公司要找出某个软件的bugs和subcomponents,这个软件一共有n个bugs和s个subcomponents,每次他都能同时随机发现1个bug和1个subcompon ...
- 期望DP
BZOJ 1415 #include <iostream> #include <cstring> #include <algorithm> #include < ...
随机推荐
- JavaCSV之读CSV文件
Java在进行数据处理,有时候难免有进行CSV文件的操作,这里采用了JavaCSV读CSV文件. 1.准备工作 (1)第三方包库下载地址:https://sourceforge.net/project ...
- hihoCoder_1445_后缀自动机二·重复旋律5
#1445 : 后缀自动机二·重复旋律5 时间限制:10000ms 单点时限:2000ms 内存限制:512MB 描述 小Hi平时的一大兴趣爱好就是演奏钢琴.我们知道一个音乐旋律被表示为一段数构成的数 ...
- oracle goldengate安装
1.ftp工具上传ogg112101_fbo_ggs_Linux_x64_ora11g_64bit.zip分别到source和target服务器 [oracle@localhost mnt]$ ll ...
- 介绍一种android的裸刷机方法(fastboot刷机实质)
fastboot刷机的前提是你的开发板uboot良好并能正常启动进入fastboot模式,你的开发版的nand分区已存在.对于Android的uboot而言, 已经实现了fastboot命令,当你 ...
- ClassicLink互通原理
ClassicLink概述_ClassicLink_用户指南_专有网络 VPC-阿里云 https://help.aliyun.com/document_detail/65412.html Class ...
- Delphi中那些容易混淆的基础(@、^、Addr、Pointer,Move、CopyMemory,GetMem和FreeMem、GetMemory和FreeMemory、New和Dispose、StrAlloc和StrDispose、AllocMem)
@.^.Addr.Pointer Delphi(Pascal)中有几个特殊的符号,如@.^等,弄清楚这些符号的运行,首先要明白Delphi指针的一些基础知识:指针,是一个无符号整数(unsigned ...
- Openstack(九)部署nova服务(控制节点)
9.1nova服务介绍 nova是openstack最早的组件之一,nova分为控制节点和计算节点,计算节点通过nova computer进行虚拟机创建,通过libvirt调用kvm创建虚拟机,nov ...
- 排序问题Java
package zhuzhuangtu; import java.util.*; import java.io.*; public class Main{ public static void mai ...
- cocos代码研究(9)ProgressTimer类学习笔记
理论部分 ProgressTimer是Node的子类. 该类根据百分比来渲染显示内部的Sprite对象. 变化方向包括径向,水平或者垂直方向. 代码部分 Type getType () const获取 ...
- Codeforces Round #275 (Div. 2) 题解
A 题: 说的是在(LR) 之间找出ab互质 bc 互质 ac 不互质的 3个数 数据量小直接暴力 #include <iostream> #include <cstdio> ...