题目链接:http://poj.org/problem?id=2096

题目大意:有n种bug,有s个子系统。每天能够发现一个bug,属于一个种类并且属于一个子系统。问你每一种bug和每一个子系统都发现bug需要多少天。

设dp[i][j]为现在发现了i种bug,在j个子系统内,到目标状态需要的期望天数。

则dp[n][s] = 0,因为已经发现了n种bug在s个子系统内,不需要额外的天数了。

dp[i][j]可以转移到如下状态:

dp[i][j]:新发现的bug在已经发现的i种,已经发现的j个子系统内。概率为: (i/n)*(j/s)

dp[i+1][j]:新发现的bug在没有发现的种类中,但是在已经发现的j个子系统内。概率为 ( (n-i)/n ) * (j/s)

dp[i][j+1]:新发现的bug在已经发现的种类中,但是不在已经发现的j个子系统内。概率为 (i/n)*((s-j)/s)

dp[i+1][j+1]:新发现的bug既不在已经发现的种类中,并且也不在已经发现的j个子系统内。概率为 ( (n-i)/n ) * ( (s-j)/s )

状态转移:

dp[i][j] = dp[i][j] * (i/n)*(j/s) + dp[i+1][j] * ( (n-i)/n ) * (j/s) + dp[i][j+1]*(i/n)*((s-j)/s) + dp[i+1][j+1] * ( (n-i)/n ) * ( (s-j)/s ) + 1

 ///#pragma comment(linker, "/STACK:102400000,102400000")
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <cmath>
#include <numeric>
#include <iterator>
#include <iostream>
#include <cstdlib>
#include <functional>
#include <queue>
#include <stack>
#include <string>
#include <cctype>
using namespace std;
#define PB push_back
#define MP make_pair
#define SZ size()
#define ST begin()
#define ED end()
#define CLR clear()
#define ZERO(x) memset((x),0,sizeof(x))
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
const double EPS = 1e-; const int MAX_N = ;
int n,s;
double f[MAX_N][MAX_N]; int main(){
while(~scanf("%d%d",&n,&s)){
f[n][s] = 0.0;
for(int i=n;i>=;i--){
for(int j=s;j>=;j--){
if( n*s==i*j ) continue;
f[i][j] = 1.0*(f[i+][j]*(n-i)*j+f[i][j+]*i*(s-j)+f[i+][j+]*(n-i)*(s-j)+n*s)/(n*s-i*j);
}
}
printf("%.4f\n",f[][]);
} return ;
}

[POJ2096] Collecting Bugs (概率dp)的更多相关文章

  1. POJ2096 Collecting Bugs(概率DP,求期望)

    Collecting Bugs Ivan is fond of collecting. Unlike other people who collect post stamps, coins or ot ...

  2. poj 2096 Collecting Bugs (概率dp 天数期望)

    题目链接 题意: 一个人受雇于某公司要找出某个软件的bugs和subcomponents,这个软件一共有n个bugs和s个subcomponents,每次他都能同时随机发现1个bug和1个subcom ...

  3. poj2096 Collecting Bugs[期望dp]

    Collecting Bugs Time Limit: 10000MS   Memory Limit: 64000K Total Submissions: 5394   Accepted: 2670 ...

  4. poj 2096 Collecting Bugs 概率dp 入门经典 难度:1

    Collecting Bugs Time Limit: 10000MS   Memory Limit: 64000K Total Submissions: 2745   Accepted: 1345 ...

  5. Collecting Bugs (概率dp)

    Ivan is fond of collecting. Unlike other people who collect post stamps, coins or other material stu ...

  6. POJ 2096 Collecting Bugs (概率DP,求期望)

    Ivan is fond of collecting. Unlike other people who collect post stamps, coins or other material stu ...

  7. Poj 2096 Collecting Bugs (概率DP求期望)

    C - Collecting Bugs Time Limit:10000MS     Memory Limit:64000KB     64bit IO Format:%I64d & %I64 ...

  8. POJ 2096 Collecting Bugs (概率DP)

    题意:给定 n 类bug,和 s 个子系统,每天可以找出一个bug,求找出 n 类型的bug,并且 s 个都至少有一个的期望是多少. 析:应该是一个很简单的概率DP,dp[i][j] 表示已经从 j ...

  9. poj2096 Collecting Bugs(概率dp)

    Collecting Bugs Time Limit: 10000MS   Memory Limit: 64000K Total Submissions: 1792   Accepted: 832 C ...

随机推荐

  1. MVCC PostgreSQL实现事务和多版本并发控制的精华

    原创文章,同步发自作者个人博客,http://www.jasongj.com/sql/mvcc/ PostgreSQL针对ACID的实现机制 事务的实现原理可以解读为RDBMS采取何种技术确保事务的A ...

  2. servlet/jsp详解

    首先谈servlet的简单定义,servlet其实就是一门web服务器端编程的技术. servlet它分两种,一种是servlet容器,所有的servlet对象都要放在servlet容器中才能被调用执 ...

  3. SpringMVC中定时器继承Task后无法对service注入问题

    最近在做一个Spring+MyBatis的一个项目,其中用到了Redis的存储,然后遇到问题是这样的: RedisTask是通过定时器来每分钟像数据库里推送的,于是就有了 public class R ...

  4. 自定义ANDROID中EDITTEXT中的HINT文本的大小

    EditText editText = (EditText) rootView.findViewById(R.id.et); // 新建一个可以添加属性的文本对象 SpannableString ss ...

  5. R包之间冲突带来的奇怪错误

    今天调试一个paper的代码,出现很奇怪的错误: qh2 <- mydf %>% filter(date >= as.Date('2013-08-14'),date <= as ...

  6. NOIP2016日记

    今天下午2:30~4:30考NOIP2016..我4:00前久出来了,没仔细检查.. 错了两道基础题..(T_T)  >_< 至少能过..就这样吧..努力复赛!!

  7. 印刷电路板(PCB)的材料

    以玻璃为基础材料的板材可以在高达150℃到250℃的温度下使用.可选的介质材料有: FR4,介电常数ε0为4.6 环氧材料,介电常数ε0为3.9: 聚酰亚胺,介电常数ε0为4.5. 另外,以聚四氟乙烯 ...

  8. linux显示器常见设置

    1. 设置系统默认的分辨率 xrandr  命令: > xrandr Screen 0: minimum 1 x 1, current 1920 x 1080, maximum 8192 x 8 ...

  9. 在datagrid中实现单击行选择整行

    首先添加列:<asp:ButtonColumn Text="选择" CommandName="Select" Visible="False&qu ...

  10. UISegmentedControl和UIStepper的使用

    UISegmentedControl:分栏控件,常用的属性和方法是 1.tintColor:控制分栏控件的颜色风格 2.insertSegmentWithTitle(Image):插入分栏标题(图片) ...