POJ 2096 Collecting Bugs(概率DP)
来源:互联网 发布:ssh 端口修改 编辑:程序博客网 时间:2024/05/23 10:24
题意:一个人要找BUG,现在有n个种类,s个子系统。每个BUG有两个属性,一个是每个BUG属于一个子系统和一个分类,问发现n种BUG并且每个子系统都有BUG的平均天数
思路:
期望==概率*值
所以只需要求出所有情况的概率就行了
dp[i][j]代表已经发现了i个种类和j个子系统的BUG
现在有四种情况
1.发现的BUG是属于之前的种类并且属于之前的子系统
2.发现的BUG是属于之前的种类并且不属于之前的子系统
3.发现的BUG是不属于之前的种类并且属于之前的子系统
4.发现的BUG是不属于之前的种类并且不属于之前的子系统
四种情况发生的概率分别统计一下
dp[i][j]=(1+dp[i+1][j] * (n-i) * j/x+dp[i][j+1] * i * (s-j)/x+dp[i+1][j+1] * (n-i) * (s-j)/x)/(1-i * j/x);
#include<stdio.h>#include<string.h>#include<iostream>#include<algorithm>#include<math.h>#include<queue>#include<stack>#include<string>#include<vector>#include<map>#include<set>using namespace std;#define rfor(i,a,b) for(i=a;i<=b;++i)#define lfor(i,a,b) for(i=a;i>=b;--i)#define sfor(i,a,h) for(i=h[a];i!=-1;i=e[i].next)#define mem(a,b) memset(a,b,sizeof(a))#define mec(a,b) memcpy(a,b,sizeof(b))#define cheak(i) printf("%d ",i)#define min(a,b) (a>b?b:a)#define max(a,b) (a>b?a:b)#define inf 0x3f3f3f3f#define lowbit(x) (x&(-x))typedef long long LL;#define maxn 1005#define maxm maxn*maxn#define lson(x) (splay[x].son[0])#define rson(x) (splay[x].son[1])double dp[maxn][maxn];int main(){ int i,j,n,s; scanf("%d%d",&n,&s); dp[n][s]=0; lfor(i,n,0) { lfor(j,s,0) { if(i==n&&j==s) continue; double x=n*s*1.0; dp[i][j]=(1+dp[i+1][j]*(n-i)*j/x+dp[i][j+1]*i*(s-j)/x+dp[i+1][j+1]*(n-i)*(s-j)/x)/(1-i*j/x); } } printf("%.4f\n",dp[0][0]); return 0;}
0 0
- poj 2096 Collecting Bugs (概率dp)
- POJ 2096 Collecting Bugs(概率DP)
- POJ 2096 Collecting Bugs(概率dp)
- POJ 2096 Collecting Bugs(概率DP)
- POJ 2096 Collecting Bugs(概率DP)
- poj 2096 Collecting Bugs(概率dp)
- POJ 2096 Collecting Bugs(概率DP)
- POJ 2096 Collecting Bugs (概率DP)
- POJ-2096 Collecting Bugs (概率DP)
- poj 2096 Collecting Bugs(概率DP)
- poj 2096 Collecting Bugs (概率DP)
- POJ 2096 Collecting Bugs 概率DP
- 概率dp-poj-2096-Collecting Bugs
- poj 2096 Collecting Bugs(概率DP)
- 概率dp POJ 2096 Collecting Bugs
- POJ-2096 Collecting Bugs 简单概率DP
- poj 2096 Collecting Bugs(概率dp)
- POJ 2096 Collecting Bugs (概率dp)
- 会话的四种跟踪技术
- leetcode之Best Time to Buy and Sell Stock II
- Android Studio快捷键
- MySQL 时间和日期函数
- 使用stl for_each的三种方法
- POJ 2096 Collecting Bugs(概率DP)
- 六种值得学习的android开发框架
- 【DP+斜率优化】[HNOI2008][HYSBZ/BZOJ1010]玩具装箱toy
- CSS中position属性
- java排序中用到的两种比较方式:Comparable,Comparator
- JavaScript模式-temp
- html5学习心得【缓慢更新】
- 例题6-2 UVA 514 - Rails (铁轨)
- MySQL知识(一)——数据库概念及基本操作