[POJ2096] Collecting Bugs (概率dp)
题目链接: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)的更多相关文章
- POJ2096 Collecting Bugs(概率DP,求期望)
Collecting Bugs Ivan is fond of collecting. Unlike other people who collect post stamps, coins or ot ...
- poj 2096 Collecting Bugs (概率dp 天数期望)
题目链接 题意: 一个人受雇于某公司要找出某个软件的bugs和subcomponents,这个软件一共有n个bugs和s个subcomponents,每次他都能同时随机发现1个bug和1个subcom ...
- poj2096 Collecting Bugs[期望dp]
Collecting Bugs Time Limit: 10000MS Memory Limit: 64000K Total Submissions: 5394 Accepted: 2670 ...
- poj 2096 Collecting Bugs 概率dp 入门经典 难度:1
Collecting Bugs Time Limit: 10000MS Memory Limit: 64000K Total Submissions: 2745 Accepted: 1345 ...
- Collecting Bugs (概率dp)
Ivan is fond of collecting. Unlike other people who collect post stamps, coins or other material stu ...
- 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 (概率DP求期望)
C - Collecting Bugs Time Limit:10000MS Memory Limit:64000KB 64bit IO Format:%I64d & %I64 ...
- POJ 2096 Collecting Bugs (概率DP)
题意:给定 n 类bug,和 s 个子系统,每天可以找出一个bug,求找出 n 类型的bug,并且 s 个都至少有一个的期望是多少. 析:应该是一个很简单的概率DP,dp[i][j] 表示已经从 j ...
- poj2096 Collecting Bugs(概率dp)
Collecting Bugs Time Limit: 10000MS Memory Limit: 64000K Total Submissions: 1792 Accepted: 832 C ...
随机推荐
- Maven 学习-入门
在进行Java开发的过程中,我接触到了Maven这套构建工具.所以,花费了点时间学习了一下这套构建工具,在学习过程中学习到的有关Maven的知识,在这里分享给大家. 什么是Maven 首先,在介绍Ma ...
- forEach遍历数组实例
forEach()取出数组中2的倍数和3的倍数的数 //for IE if(!Array.prototype.forEach){ Array.prototype.forEach = function( ...
- Less函数说明
索引 escape(@string); // 通过 URL-encoding 编码字符串 e(@string); // 对字符串转义 %(@string, values...); // 格式化字符串 ...
- HDU 3342 Legal or Not(判断是否存在环)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3342 Legal or Not Time Limit: 2000/1000 MS (Java/Othe ...
- Bootstrap-17
导入JavaScript插件: 一次性导入:Bootstrap提供了一个单一的文件,这个文件包含了Bootstrap的所有JavaScript插件,即bootstrap.js <!—导入jQue ...
- ns115 step by step
一,安装环境: sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev lib ...
- Examples of complexity pattern
O(1):constant - the operation doesn't depend on the size of its input, e.g. adding a node to the tai ...
- Codeforces Round #361 Jul.6th B题 ☺译
最近迈克忙着考前复习,他希望通过出门浮躁来冷静一下.迈克所在的城市包含N个可以浮躁的地方,分别编号为1..N.通常迈克在家也很浮躁,所以说他家属于可以浮躁的地方并且编号为1.迈克从家出发,去一些可以浮 ...
- go语言的命令行库
命令行应用通常很小,程序猿们也不喜欢为它编写注释.所以一些额外的工作,如解析参数有个合理的库来帮忙做就好了.https://github.com/urfave/cli 这个项目因此而生.安装:go g ...
- 查看死锁 的存储过程 ,工具存储过程 sp_who_lock
http://blog.sina.com.cn/s/blog_95b5eb8c010162jp.html if exists (select * from dbo.sysobjects where i ...