POJ 2096 【期望DP】
题意:
有n种选择,每种选择对应m种状态。每种选择发生的概率相等,每种选择中对应的每种状态发生的概率相等。
求n种选择和m种状态中每种至少发生一次的期望。
期望DP好别扭啊。要用倒推的方法。
dp[i][j]表示已经发生了i种选择,j种状态。
那么由dp[n][m]这个时刻到最终时刻的期望是0.
而我们的起始时刻是dp[0][0]。
而dp[i][j]可以转移到四种情况,
1 dp[i][j]本身
2 dp[i+1][j]
3 dp[i][j+1]
4 dp[i+1][j+1]
那么dp[i][j]表示的期望是他能够转移到别的所有的情况的期望乘其权值的和。
好的。这大概就是期望DP的精髓了...
#include<stdio.h>
#include<string.h>
double dp[][];
int main()
{
int n,m;
scanf("%d%d",&n,&m);
memset(dp,,sizeof(dp));
for(int i=n;i>=;i--)
{
for(int j=m;j>=;j--)
{
if(i!=n||j!=m)
dp[i][j]=(dp[i][j+]*(m-j)*i/((double)(m*n))+dp[i+][j]*(n-i)*j/((double)(m*n))+dp[i+][j+]*(n-i)*(m-j)/((double)(m*n))+)/((double)(-((double)(i*j))/(m*n)));
}
}
printf("%.4lf\n",dp[][]);
}
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 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 < ...
随机推荐
- Redis配制说明
配置文件参数说明: 1. Redis默认不是以守护进程的方式运行,可以通过该配置项修改,使用yes启用守护进程 daemonize no 2. 当Redis以守护进程方式运行时,Redis默 ...
- SourceInsight支持Python代码阅读
这个话题,很简单,主要是要有一个插件Python.CLF,这个文件可以从我的GitHub上下载.然后,参照下面的图片显示的步骤,就很快搞定! 具体的步骤,看下面的三张图片,顺序编号了,从1到9,对照着 ...
- select case when
SELECT CASE WHEN dc.defect_code_name IS NOT NULL THEN dc.defect_code_name WHEN sf.second_defect_leve ...
- SPOJ #453. Sums in a Triangle (tutorial)
It is a small fun problem to solve. Since only a max sum is required (no need to print path), we can ...
- 剑指offer系列35----序列化二叉树
[题目] * 请实现两个函数,分别用来序列化和反序列化二叉树 * 1 / \ 2 3 /\ /\4 5 6 7 * * 序列化的结果是1,2,#,#,3,4,#,7,#,#,5,#,#,. * 而反序 ...
- android学习笔记39——使用原始资源
原始资源 android中没有专门提供管理支持的类型文件,都被称为原始资源.例如:声音资源... android原始资源存放位置: 1.res/raw,android SDK会处理该目录下的原始资源, ...
- postgresql数据库文件目录
不同的发行版位置不同 查看进程 ps auxw | grep postgres | grep -- -D 找到默认的目录 /usr/lib/postgresql/9.4/bin/postgres -D ...
- erlang远程加载模块须知
erlang加载本地beam到远程节点,需要把依赖库一个个手动加载,否则他不会自动加载. 另外,创建lib的话,使用 rebar-creator create-lib
- C#如何使用HttpWebRequest、HttpWebResponse模拟浏览器抓取网页内容
public string GetHtml(string url, Encoding ed) { string Html = string.Empty;//初始化新的webRequst HttpWeb ...
- POJ 3162 Walking Race 树形DP+线段树
给出一棵树,编号为1~n,给出数m 漂亮mm连续n天锻炼身体,每天会以节点i为起点,走到离i最远距离的节点 走了n天之后,mm想到知道自己这n天的锻炼效果 于是mm把这n天每一天走的距离记录在一起,成 ...