【poj 2151】Check the difficulty of problems 概率dp
来源:互联网 发布:淘宝小白帽 编辑:程序博客网 时间:2024/06/07 06:31
题意:m到题T个队伍,给出每一个队伍做出每一道题的概率,询问所有队伍都至少解决一道题目且做的最多的队伍做的题目大于等于n的概率。
感觉还是一道很有趣的dp。首先考虑求至少每一个队伍都至少解决一道题目可以怎么解决?这个很简单,可以先算出每个队一道题都解决不了,然后用1减去就可以了。现在考虑至少有一个队伍要求解决的题目的数目超过n该如何解决,类似于刚才的想法我们社p为所有队伍都解决不了超过等于n道题的概率所以最后的答案就是p1*(1-p)换出来就是p1-p1*p
可以用f[i][j][k]表示第i个人对于钱j道题解决了k道题的概率与处理出每一个人做k道题的概率(即f[i][m][k])方程:
f[i][j][k]=f[i][j-1][k]*(1-p[j])+f[i][j-1][k-1]*p[j]
为了方便令dp[i][j]表示第i个人最多做j道题的概率(用刚才的转移就好了)
最后统计一下答案就好了
#include<cstdio>#include<cstring>#include<iostream>#define clean(a) memset(a,0,sizeof(a))using namespace std;int T,m,n;double f[1002][32][32],dp[1002][32],mat[1002][32];//f[i][j][k]表示对于第i个队伍 前j个题目解出了k道题目的概率//dp[i][j] 表示第i个队伍至少做出j道题目的几率 int main(){while(scanf("%d%d%d",&m,&T,&n)&&(m+T+n)){clean(f),clean(dp),clean(mat);for(int i=1;i<=T;i++){f[i][0][0]=1.0;for(int j=1;j<=m;j++)scanf("%lf",&mat[i][j]);}for(int i=1;i<=T;i++){for(int j=1;j<=m;j++){for(int k=0;k<=j;k++){f[i][j][k]=f[i][j-1][k]*(1-mat[i][j]);if(k!=0)f[i][j][k]+=f[i][j-1][k-1]*mat[i][j];}}}for(int i=1;i<=T;i++){dp[i][0]=f[i][m][0];for(int j=1;j<=m;j++)dp[i][j]=f[i][m][j]+dp[i][j-1];}double ans1=1,ans2=1;for(int i=1;i<=T;i++){ans1*=1-dp[i][0];ans2*=(dp[i][n-1]-dp[i][0]);}printf("%.3lf\n",ans1-ans2);}return 0;}/*2 2 20.9 0.91 0.90 0 0*/
0 0
- POJ 2151 Check the difficulty of problems 概率DP
- poj 2151 Check the difficulty of problems 概率dp
- POj 2151 Check the difficulty of problems 概率DP
- POJ 2151 Check the difficulty of problems(概率DP)
- 概率dp POJ 2151 Check the difficulty of problems
- poj 2151 Check the difficulty of problems(概率dp)
- poj 2151 Check the difficulty of problems(概率dp)
- POJ 2151 Check the difficulty of problems(概率dp)
- poj 2151 Check the difficulty of problems 概率dp
- poj 2151 Check the difficulty of problems(概率DP)
- poj 2151 Check the difficulty of problems(概率dp)
- poj 2151 Check the difficulty of problems 概率dp
- poj 2151 Check the difficulty of problems (概率dp)
- POJ 2151 Check the difficulty of problems (概率dp)
- poj 2151 Check the difficulty of problems (概率DP)
- poj 2151 Check the difficulty of problems (dp,概率)
- Check the difficulty of problems - POJ 2151 概率dp
- POJ 2151 Check the difficulty of problems 概率dp
- idea中properties配置文件中显示utf-8编码时,怎么办?
- Path Sum II
- java 处理高并发(转载)
- 解决powerdesigner连接mysql时连接不上的问题
- Java 遍历List ConcurrentModificationException 异常解析
- 【poj 2151】Check the difficulty of problems 概率dp
- express不是内部命令或者外部命令
- session、cookie与“记住我的登录状态”的功能的实现
- Swift3.0带来的变化汇总系列一——字符串与基本运算符中的变化
- 检查服务器是否支持ipv6
- SD间接合作伙伴功能
- Linux 开机提示kernel panic...解决方法
- 每天一个linux命令(10):cat 命令
- 数据结构经典算法学习之八枚银币(简单决策树)