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是赢 ...
随机推荐
- File类,递归
File类 File文件和目录路径名的抽象表示形式.即,Java中把文件或者目录(文件夹)都封装成File对象. File类包含 路径 path E:\... 目录 direct ...
- ES6初识-解构赋值
数组解构赋值 [a,b]=[1,2]; . 方法返回 function f(){ return [1,2] } let a,b; [a,b]=f();//a=1,b=2 function f1() ...
- JavaScript的算术、赋值、关系运算符的讲解
JS中的运算符分为:算术/赋值/关系/逻辑/字符串 算术运算符: +加法 -减法 *乘法 /除法 %取余 var a = 1, b = 2; a + b = 3 ...
- Python线程创建与使用
Python多为线程编程提供了两个简单明了的模块:thread和threading,Python3中已经不存thread模块,已经被改名为_thread,实际优先使用 threading模块. 1.P ...
- (转)在图像处理中,散度 div 具体的作用是什么?
出处http://www.zhihu.com/question/24591127 按:今天看到这篇文章,有点感慨,散度这个概念我初次接触到至少应该是在1998年,时隔这么多年后看到这篇文章,真的 佩服 ...
- php-5.6.26源代码 - 如何用C语言支持“类似异常”机制
代码编写在文件php-\Zend\zend.h #define zend_bailout() _zend_bailout(__FILE__, __LINE__) #ifdef HAVE_SIGSETJ ...
- 使用PHP生成分享图片
小程序导航 wq.xmaht.top 假设代码中用到的资源文件夹在当前code_png目录下: /** * 分享图片生成 * @param $gData 商品数据,array * @param $co ...
- bin/postconf: error while loading shared libraries: libmysqlclient
今天在编译安装postfix的时候 make install 出现如下错误 bin/postconf: error while loading shared libraries: libmysqlcl ...
- POJ 1222 反转
EXTENDED LIGHTS OUT Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12469 Accepted: 7 ...
- 基于HDP版本的YDB安装部署(转)
第三章 YDB依赖环境准备 一.硬件环境 硬件如何搭配,能做到比较高的性价比,不存在短板.合理的硬件搭配,对系统的稳定性也很关键. 1.CPU不是核数越高越好,性价比才是关键. 经常遇到很多的企业级客 ...