有 T(1<T<=1000) 支队伍和 M(0<M<=30) 个题目,已知每支队伍 i 解决每道题目 j 的的概率 p[i][j],现在问:每支队伍至少解决一道题,且解题最多的队伍的题目数量不少于 N(0<N<=M) 的概率是多少?

p[i][j]表示第i个队伍做对第j题的概率。dp[i][j][k]表示第i个队伍在前j题中做对了k道的概率。
dp[i][j][k] = dp[i][j-1][k-1]*(p[i][j])+dp[i][j-1][k]*(1-p[i][j]);
再求出每个队都至少做对 1 道题的概率:ans1 *= 1 - dp[i][m][0];
求出每个队都只做对了 1 ~ n-1 题的概率 ans2即:(把每个队做对 1 ~ n-1 题的概率相加后,并把每个队的结果相乘);
然后两者相减ans1-ans2

 #include<stdio.h>
#include<stdlib.h>
#include<string.h>
int M,T,N;
double p[][];
double dp[][][];
double sum[][];
int main() {
scanf("%d %d %d",&M,&T,&N);
while(M&&N&&T){
memset(p,,sizeof(p));
for(int i=;i<=T;i++){
for(int j=;j<=M;j++){
scanf("%lf",&p[i][j]);
}
}
memset(dp,,sizeof(dp));
for(int i=;i<=T;i++){
dp[i][][]=p[i][];
dp[i][][]=-p[i][]; }
for(int i=;i<=T;i++){
for(int j=;j<=M;j++){
for(int k=;k<=j;k++){
dp[i][j][k]=dp[i][j-][k]*(1.0-p[i][j]);
if(k>) dp[i][j][k]+=dp[i][j-][k-]*p[i][j];
}
}
}
memset(sum,,sizeof(sum));
for(int i=;i<=T;i++){
sum[i][]=dp[i][M][];
for (int j=;j<=M;j++) {
sum[i][j]=sum[i][j-]+dp[i][M][j];
}
}
double ans1=1.0,ans2=1.0;
for(int i=; i<=T; i++) {
ans1*=sum[i][M]-sum[i][];
ans2*=(sum[i][N-]-sum[i][]);
}
printf("%.3lf\n",ans1-ans2);
scanf("%d %d %d",&M,&T,&N);
} return ;
}
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 5766   Accepted: 2515

Description

Organizing a programming contest is not an easy job. To avoid making the problems too difficult, the organizer usually expect the contest result satisfy the following two terms: 
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

The 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

For 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

Check the difficulty of problems - poj 2151 (概率+DP)的更多相关文章

  1. POJ 2151 Check the difficulty of problems (动态规划-可能DP)

    Check the difficulty of problems Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4522   ...

  2. poj 2151 概率DP(水)

    Check the difficulty of problems Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 5750   ...

  3. POJ 2151 概率DP

    主要的子问题是每一个队伍有一个做出题目的概率,求做出k个题目的概率.简单的简单的组合数DP.想清楚即可. 1: #include <iostream> 2: #include <cs ...

  4. POJ 2151 Check the difficulty of problems 概率dp+01背包

    题目链接: http://poj.org/problem?id=2151 Check the difficulty of problems Time Limit: 2000MSMemory Limit ...

  5. 【POJ】2151:Check the difficulty of problems【概率DP】

    Check the difficulty of problems Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8903   ...

  6. [ACM] POJ 2151 Check the difficulty of problems (概率+DP)

    Check the difficulty of problems Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4748   ...

  7. Check the difficulty of problems(POJ 2151)

    Check the difficulty of problems Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 5457   ...

  8. POJ 2151 Check the difficulty of problems

    以前做过的题目了....补集+DP        Check the difficulty of problems Time Limit: 2000MS   Memory Limit: 65536K ...

  9. Check the difficulty of problems

    Check the difficulty of problems Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 5830 Acc ...

随机推荐

  1. Linux环境Nginx安装与调试以及PHP安装

    linux版本:64位CentOS 6.4 Nginx版本:nginx1.8.0 php版本:php5.5.28 1.编译安装Nginx 官网:http://wiki.nginx.org/Instal ...

  2. IOS APP 上传到AppStore

    由于第一次接触要把 app 上传到 AppStore 比较棘手,很多地方不懂,研究了 大半天 终于给上传成功了,现在坐等审核吧,首先把上传到AppStore的流程 整理下 : 第一 :准备证书 (要确 ...

  3. [转] 一篇好文 ---steve jobs (stay hungry, stay foolish)

    斯蒂夫•保罗•乔布斯(Steve Paul Jobs,1955年2月24日出生-)是蘋果電腦的現任首席執行長(首席执行官)兼創辦人之一.同時也是Pixar動畫公司的董事長及首席執行長.这是他2005在 ...

  4. EffectiveJava(27)优先考虑使用泛型方法

    泛型方法也可以从泛型类中获得同等收益,泛型方法的转换也十分简单,只需将原生态类型改为泛型,基本就可以解决问题 如:一个返回两个集合的联合 public static Set union(Set s1, ...

  5. java实现快速排序算法

    1.算法概念. 快速排序(Quicksort)是对冒泡排序的一种改进.由C. A. R. Hoare在1962年提出.2.算法思想. 通过一趟排序将要排序的数据分割成独立的两部分,其中一部分的所有数据 ...

  6. BEA公司的weblogic是什么?有什么特点?

    转自:http://zhidao.baidu.com/link?url=J9obKwHhuh1sdLoBC3pILeaq1nz_tcpScggBNeS3D0GzAz9FI002vlS2xxJD4_z6 ...

  7. 倍福TwinCAT(贝福Beckhoff)常见问题(FAQ)-如何在程序中添加注释

    在TwinCAT2中,(*中间输入注释*),也可以用这种方法批量注释,在TwinCAT3中,使用//即可     更多教学视频和资料下载,欢迎关注以下信息: 我的优酷空间: http://i.youk ...

  8. UISearchbar placeholder 文本和icon居左 iOS7

    在iOS7 下测试了一些方法,发现还是攺变不了文本的居左,最后发现了一个nb的招: _searchBar = [[UISearchBar alloc]initWithFrame:CGRectZero] ...

  9. CSS3文本溢出

    text-overflow: text-overflow:clip | ellipsis; clip:剪切多余的文字. ellipsis:文本溢出时显示省略标记. 要实现文本溢出剪切显示省略标记,还需 ...

  10. raspberry pi install iceweasel

    sudo apt-get update sudo apt-get upgrade sudo apt-get install iceweasel