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 < ...
随机推荐
- C# get post 的方法
#region GET POST /// <summary> /// Get String data = GetString(URL , "PKEY=" + Pkeyl ...
- SQL---->mySQl数据库1------表内容的增删改查
增: insert into user(id,username,birthday,entry_date,job,salary,resume) values(1,'aaaa','1995-12-10', ...
- 使用log4net做应用程序全局日志记录保存在数据库中
几乎所有的大型应用都会有自己的用于跟踪调试的API.因为一旦程序被部署以后,就不太可能再利用专门的调试工具了.然而一个管理员可能需要有一套强大的日志系统来诊断和修复配置上的问题.经验表明,日志记录往往 ...
- os模块os.walk() 方法和os.path.join()的简单使用
os.walk: http://www.runoob.com/python/os-walk.html os.path.join: https://blog.csdn.net/zmdzbzbhs ...
- ERROR 2002 (HY000): Can't connect to local MySQL server through socket
原文链接:https://blog.csdn.net/u011262253/article/details/82802157 一.错误现场还原: 下面我们通过三种方式来连接,然后观察提示的错误信息: ...
- [原创]chromium源码阅读-进程间通信IPC.消息的接收与应答
chromium源码阅读-进程间通信IPC.消息的接收与应答 chromium源码阅读-进程间通信IPC.消息的接收与应答 介绍 chromium进程间通信在win32下是通过命名管道的方式实现的 ...
- ppt 文字按笔画进入。
1:在word里面写一个字(艺术字或非艺术字都可),字体格式设置为 楷体_gb23212, 没有则下载安装,http://www.cnblogs.com/liyafei/p/8747992.html ...
- Spark Streaming带状态更新
带状态的更新是使用的updateStateByKey方法,里面传入一个函数,函数要自己写,注意需要设置checkpoint import org.apache.spark.streaming.kafk ...
- Sql Server查询同一ID 时间较大的一条数据
- NOSQL数据库-Redis
官方提倡使用Linux版的Redis,所以官网值提供了Linux版的Redis下载,我们可以从GitHub上下载window版的Redis,具体链接地址如下: · 官网下载地址:http://redi ...