poj 2151 概率DP(水)
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 5750 | Accepted: 2510 |
Description
1. All of the teams solve at least one problem.
2. The champion (One of those teams that solve the most problems) solves at least a certain number of problems.
Now the organizer has studied out the contest problems, and through
the result of preliminary contest, the organizer can estimate the
probability that a certain team can successfully solve a certain
problem.
Given the number of contest problems M, the number of teams T, and
the number of problems N that the organizer expect the champion solve at
least. We also assume that team i solves problem j with the probability
Pij (1 <= i <= T, 1<= j <= M). Well, can you calculate the
probability that all of the teams solve at least one problem, and at the
same time the champion team solves at least N problems?
Input
input consists of several test cases. The first line of each test case
contains three integers M (0 < M <= 30), T (1 < T <= 1000)
and N (0 < N <= M). Each of the following T lines contains M
floating-point numbers in the range of [0,1]. In these T lines, the j-th
number in the i-th line is just Pij. A test case of M = T = N = 0
indicates the end of input, and should not be processed.
Output
each test case, please output the answer in a separate line. The result
should be rounded to three digits after the decimal point.
Sample Input
2 2 2
0.9 0.9
1 0.9
0 0 0
Sample Output
0.972
题意:在acm比赛中,n题,t队。给出每个队做对每题的概率,问每队至少对一题,至少有一队做对至少m题的概率。(本解题报告中的n,m与原题中相反)
分析:dp,f[i][j]表示第i个队伍做对第j题的概率。g[i][j][k]表示第i个队伍对于前j题而言做对k道的概率。
g[i][j][k] = g[i][j - 1][k - 1] * (f[i][j]) + g[i][j - 1][k] * (1 - f[i][j]);
有了所有的g,我们就可以求出每个队至少做对1题的概率:ans *= 1 - g[i][n][0];
再减去每个队都只做对1~m-1题的概率(把每个队做对1~m-1题的概率加和,并把各队结果相乘)
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
double f[][];
double dp[][][];
int main(){
int n,t,m;
while(scanf("%d%d%d",&n,&t,&m)!=EOF){
if(n==&&t==&&m==)
break;
memset(f,,sizeof(f));
memset(dp,,sizeof(dp));
for(int i=;i<t;i++){
for(int j=;j<=n;j++)
scanf("%lf",&f[i][j]);
} for(int i=;i<t;i++){
dp[i][][]=;
for(int j=;j<=n;j++){
dp[i][j][]=dp[i][j-][]*(-f[i][j]);
for(int k=;k<=j;k++)
dp[i][j][k]=dp[i][j-][k-]*f[i][j]+dp[i][j-][k]*(-f[i][j]);
}
} double ans=;
for(int i=;i<t;i++)
ans*=(-dp[i][n][]); double temp=;
for(int i=;i<t;i++){
double sum=;
for(int j=;j<m;j++)
sum+=dp[i][n][j];
temp*=sum;
} printf("%.3lf\n",ans-temp); }
return ;
}
poj 2151 概率DP(水)的更多相关文章
- POJ 2151 概率DP
主要的子问题是每一个队伍有一个做出题目的概率,求做出k个题目的概率.简单的简单的组合数DP.想清楚即可. 1: #include <iostream> 2: #include <cs ...
- Check the difficulty of problems - poj 2151 (概率+DP)
有 T(1<T<=1000) 支队伍和 M(0<M<=30) 个题目,已知每支队伍 i 解决每道题目 j 的的概率 p[i][j],现在问:每支队伍至少解决一道题,且解题最多的 ...
- Codeforces 148D 一袋老鼠 Bag of mice | 概率DP 水题
除非特别忙,我接下来会尽可能翻译我做的每道CF题的题面! Codeforces 148D 一袋老鼠 Bag of mice | 概率DP 水题 题面 胡小兔和司公子都认为对方是垃圾. 为了决出谁才是垃 ...
- 13年山东省赛 The number of steps(概率dp水题)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud The number of steps Time Limit: 1 Sec Me ...
- poj 3071 Football (概率DP水题)
G - Football Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit ...
- POJ 2096 (概率DP)
题目链接: http://poj.org/problem?id=2096 题目大意:n种bug,s个子系统.每天随机找一个bug,种类随机,来自系统随机.问找齐n种bug,且每个子系统至少有一个bug ...
- POJ 3701 概率DP
给定2^n 支足球队进行比赛,n<=7. 队伍两两之间有一个获胜的概率,求每一个队伍赢得最后比赛的概率是多少? 状态其实都是很显然的,一开始觉得这个问题很难啊,不会.dp[i][j] 表示第i支 ...
- Scout YYF I POJ - 3744(概率dp + 矩阵快速幂)
题意: 一条路上有n个地雷,你从1开始走,单位时间内有p的概率走一步,1-p的概率走两步,问安全通过这条路的概率 解析: 很容易想到 dp[i] = p * dp[i-1] + (1 - p) * d ...
- poj 3071 概率dp
转自:cxlove 题目:有2^n个队,相邻的两两打淘汰赛,,求最后哪个队夺冠的概率最大 dp[i][j]表示第i轮的时候,第j去支队伍赢的概率. 那么dp[i][j]的前提就是i-1轮的时候,j是赢 ...
随机推荐
- prepareStatament和Statement和callableStatement的区别
关系与区别 Statement.PreparedStatement和CallableStatement都是接口(interface) Statement 1.Statement接口提供了执行语句和获取 ...
- List<T>转换为二维数组
public <T> Object[][] toArrays(List<T> data){ Object[][] o=new Object[data.size()][20]; ...
- WebSeal单点登陆
WebSeal单点登陆 作为学习整理,部分内容来自网络和官方文档. LDAP LDAP可以看作一种数据库,分为客户端和服务端.服务端是用来存放资源,客户端用来操作资源.它是一种树形存储结构,遍历起来会 ...
- 使用泛型实现对int数组或者String数组进行排序
因为是使用的泛型,我们并不确定数据类型, 对于数据的比较就不能用平时的大于或者小于. 我们需要比较对象实现Comparable接口,该接口下的compareTo()方法可以用来比大小 定义Sort类: ...
- 手机丢了怎么办?MZ给你来支招
1致电运营商挂失手机 2致电银行冻结手机网银 3手机绑定支付宝的拨95188挂失 4微信用户登录110.qq.com冻结账号 5修改微博.微信.QQ等密码 6到手机运营商处补手机卡. 一定要记住啊!手 ...
- Cloudera Manager 安装 CDH5
文档说明 本文是针对Linux CentOS6服务器与CDH5.15的安装手册. 关于CDH和ClouderaManager CDH(Cloudera's Distribution, includin ...
- springMVC集成logback日志系统
一.项目结构 项目介绍:maven搭建的web项目,实现Java日志记录功能.其中logback.xml为日志配置文件,spring-mvc-servlet.xml为spring controller ...
- form表单submit按钮提交页面不跳转
方案一 <html> <body> <form action="" method="post" target="nm_i ...
- JDK学习---深入理解java中的HashMap、HashSet底层实现
本文参考资料: 1.<大话数据结构> 2.http://www.cnblogs.com/dassmeta/p/5338955.html 3.http://www.cnblogs.com/d ...
- PLC状态机编程第五篇-状态机自动生成PLC程序
这篇比较简单了,我就直接上图了,不多废话. 一.选择求解器,一定要选择定步长的. 二.右击Chart状态机,出现图上菜单 三.左边红色的勾选择,选择右侧的菜单,然后点击Generate Code按钮, ...