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 < ...
随机推荐
- 09_android入门_采用android-async-http开源项目的GET方式或POST方式实现登陆案例
根据08_android入门_android-async-http开源项目介绍及使用方法的介绍,我们通过最常见的登陆案例进行介绍android-async-http开源项目中有关类的使用.希望对你学习 ...
- 功能更强大的格式化工具类 FormatUtils.java
package com.util; import java.text.DecimalFormat; import java.text.ParseException; import java.text. ...
- 封装类的方式访问数据库(封装字符串、json)
<?php class DBDA { public $host="localhost";//服务器地址 public $uid="root";//用户名 ...
- centos curl版本nss改成openssl
在centos 6.2的系统里面的curl支持的https是nss版本的,而不是openssl的,所以在php使用curl访问https的时候会报Unable to load client key - ...
- 【shell】if语句
单分支: #!/bin/bash rate=$(df -h|grep vg_andon-lv_root |awk '{print $5}'| cut -d "%" -f1) #ec ...
- 【python】sys.argv[]的用法
在学python的过程中,一直弄不明白sys.argv[]的意思,虽知道是表示命令行参数,但还是有些稀里糊涂的感觉. 今天又好好学习了一把,总算是大彻大悟了. Sys.argv[]是用来获取命令行参数 ...
- IE11如何采用其他低级版本调试网页
IE9的方法: 出于未知需求,用户在安装了较高版本IE浏览器(IE9)之后,又需要使用低版本的IE(7,8),为了返回较低版本,很多用户选择(不得不)卸载新版本IE,这样显得十分不科学.实际上IE9提 ...
- 调用wcf 得不到HttpWebResponse.ContentLength的长度
HttpWebRequest wreq = (HttpWebRequest)WebRequest.Create(strUrl); wreq.Timeout = _httpTimeout * ; wre ...
- Python 数据排序和列表迭代和列表推导应用
1.In-place sorting 原地排序 data=[6,4,5,2,3,1] print ('before sort', data) data.sort() print ('after sor ...
- Install Apache, PHP And MySQL On CentOS 7 (LAMP)
This tutorial shows how you can install an Apache2 webserver on a CentOS 7.0 server with PHP5 suppor ...