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是赢 ...
随机推荐
- 关于css 中position使用的浅谈
在css中有一种属性position.在W3C上我们可以找到他又一下几种属性:absolute.fixed.relative.static.inherit.但是position的使用却并不是简简单单的 ...
- Git log、diff、config 进阶
前一段时间分享了一篇<更好的 git log>简要介绍怎么美化 git log 命令,其中提到了 alias命令,今天再继续谈谈 git相关, 看看如何通过配置自己的 git config ...
- lambda函数,内置map()函数及filter()函数
8.1 lambda函数 作用及意义: 1.没必要专门定义函数,给函数起名,起到精简的效果 2.简化代码的可读性 def ds(x): return 2 * x + 1 ds(5) ---11 g ...
- HTML第二章:列表,表格,媒体元素
第二章:列表,表格,媒体元素 列表:有三种,有序列表,无序列表,定义列表 1.有序列表:<ol></ol> 列表项:<li></li&g ...
- 9、SpringBoot+Mybatis整合------动态sql
开发工具:STS 前言: mybatis框架中最具特色的便是sql语句中的自定义,而动态sql的使用又使整个框架更加灵活. 动态sql中的语法: where标签 if标签 trim标签 set标签 s ...
- 【Java】基础:常见修饰符(权限修饰符以及abstract、static、final等)与变量的描述
1. 修饰符 public.protected.private.default abstract.static.final. abstract:抽象类.抽象方法 static:静态变量.静态方法.静态 ...
- es6-promise.auto.js
使用sweetalert2的IE浏览器报错,导入文件 链接:https://pan.baidu.com/s/1mOcsN_o8m-7I7Rej1NPkiw 提取码:9xsj
- TryParse()的用法
DateTime dt = new DateTime(); DateTime.TryParse(txtName.text.trim(),out dt); string str1 = dt.ToStri ...
- JNDI整理
JNDI 什么是JNDI JNDI全称为Java Naming and Directory Interface,命名及目录查找接口,是java平台的一种标准扩展,它提供了一系列接口.类和命名空间的概念 ...
- Python简单线程间通信
本节主要举一个简单的线程间通信的例子,利用线程安全的数据结构queue.Queue保存线程间通信的内容, import queue from threading import Thread from ...