题目链接: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. cocos3.12预编译android报错RuntimeJsImpl.cpp

    从coco官网下载了cocos2d-x-3.12.zip,在gen-libs生成prebuilt时,mac ,ios 平台都正常,android报错: jni/../../Classes/ide-su ...

  2. 如何隐藏UITableView中的一项

    我最近工作中的一个iOS App中经常有在不同的场合,隐现菜单列表里某一项的需求.如果初始化的时候就去掉某一项的话,有可能让序号变化, 处理上会比较麻烦容易出错.我采用了初始化列表相同但是隐藏sect ...

  3. Java方法调用中的别名处理

    将一个对象传递到方法内部时,也会产生别名现象.//: PassObject.java// Passing objects to methods can be a bit tricky62class L ...

  4. 1-Spark高级数据分析-第一章 大数据分析

    1.1 数据科学面临的挑战 第一,成功的分析中绝大部分工作是数据预处理. 第二,迭代与数据科学紧密相关.建模和分析经常需要对一个数据集进行多次遍历.这其中一方面是由机器学习算法和统计过程本身造成的. ...

  5. Sublime Text 3 简体中文汉化包

    Sublime Text 3下载 不用说是上官方下载地址:http://www.sublimetext.com/3 Sublime Text 3 简体中文汉化包使用方法 1.将上面要求下载的subli ...

  6. touch srceen

    /etc/udev/rules.d touchrules reset

  7. Dos学习笔记(1)dir命令

    这个命令是最常用的命令,就像linux的ls一样,同样他也有很多很多optionnal field供我们选择, 看了半天,觉得自己离盲打肯定还是有很大的差距的,现在只是想体验一下dos,或者说感受下这 ...

  8. iOS分析UI利器——Reveal及简单破解方法

    Reveal作为分析APP UI的利器确实非常好用,用来查看任意UI布局也很方便 一.模拟器进行分析 1.打开Reveal(http://revealapp.com下载) 2.打开Xcode 3.Re ...

  9. epoll 反应堆

    epoll反应堆模型 ================================ 下面代码实现的思想:epoll反应堆模型:( libevent 网络编程开源库 核心思想) . 普通多路IO转接 ...

  10. JS中正则匹配的三个方法match exec test的用法

    javascript中正则匹配有3个方法,match,exec,test: match是字符串的一个方法,接收一个RegExp对象做为参数: match() 方法可在字符串内检索指定的值,或找到一个或 ...