题目链接:http://poj.org/problem?id=2151

题意:

  一次ACM比赛,有t支队伍,比赛共m道题。

  第i支队伍做出第j道题的概率为p[i][j].

  问你所有队伍都至少做出一道,并且有队伍做出至少n道的概率。

题解:

  关于【至少】问题的表示。

  

  对于每一支队伍:

    mst[i][j] = P(第i支队伍做出至多j道题)

    则 P(第i支队伍做出至少j道题) = 1 - mst[i][j-1]

  

  对于所有队伍:

    P(所有队伍至少答出一题) = ∏ (1 - mst[i][0])

    P(所有队伍答题数在1到n-1) = ∏ (mst[i][n-1] - mst[i][0])

    所以答案:

    P(所有队伍至少答出一题,且有队伍做出至少n道) = P(所有队伍至少答出一题) - P(所有队伍答题数在1到n-1)

  所以求mst数组好啦~~~

  dp[i][j][k] = probability

  i:第i支队伍

  j:考虑到前j道题(包含j)

  k:恰好做出k道

  所以 mst[i][j] = sigma(dp[i][m][0 to j])

  怎么求dp数组呢:

    转移:dp[i][j][k] = dp[i][j-1][k-1]*p[i][j] + dp[i][j-1][k]*(1-p[i][j])

    边界:dp[i][0][0] = 1, others = 0

  所以这道题:先求dp,再求mst,最后统计ans。

AC Code:

 // state expression:
// dp[i][j][k] = probability
// i: ith team
// j: jth question and before
// k: solved k questions
// mst[i][j]
// i: ith team
// j: all the teams solved at most j questions
//
// find the answer:
// P(all 1 to m) - P(all 1 to n-1)
//
// transferring:
// dp[i][j][k] = dp[i][j-1][k-1]*p[i][j] + dp[i][j-1][k]*(1-p[i][j])
//
// boundary:
// dp[i][0][0] = 1
// others = 0
//
// calculate:
// mst[i][j] = sigma dp[i][m][0 to j]
// P1 = pi (1 - mst[i][0])
// P2 = pi (mst[i][n-1] - mst[i][0])
//
// step:
// 1) cal dp
// 2) cal mst
// 3) cal ans
#include <iostream>
#include <stdio.h>
#include <string.h>
#define MAX_T 1005
#define MAX_N 35
#define MAX_M 35 using namespace std; int n,m,t;
double p1,p2;
double p[MAX_T][MAX_M];
double dp[MAX_T][MAX_M][MAX_M];
double mst[MAX_T][MAX_M]; void read()
{
for(int i=;i<=t;i++)
{
for(int j=;j<=m;j++)
{
cin>>p[i][j];
}
}
} void cal_dp()
{
memset(dp,,sizeof(dp));
for(int i=;i<=t;i++)
{
dp[i][][]=;
for(int j=;j<=m;j++)
{
for(int k=;k<=m;k++)
{
if(k->=) dp[i][j][k]+=dp[i][j-][k-]*p[i][j];
dp[i][j][k]+=dp[i][j-][k]*(-p[i][j]);
}
}
}
} void cal_mst()
{
// mst[i][j] = sigma dp[i][m][0 to j]
memset(mst,,sizeof(mst));
for(int i=;i<=t;i++)
{
for(int j=;j<=m;j++)
{
for(int k=;k<=j;k++)
{
mst[i][j]+=dp[i][m][k];
}
}
}
} void cal_ans()
{
// P1 = pi (1 - mst[i][0])
// P2 = pi (mst[i][n-1] - mst[i][0])
p1=1.0;
p2=1.0;
for(int i=;i<=t;i++)
{
p1*=(-mst[i][]);
p2*=(mst[i][n-]-mst[i][]);
}
} void solve()
{
cal_dp();
cal_mst();
cal_ans();
} void print()
{
printf("%.3f\n",p1-p2);
} int main()
{
while(cin>>m>>t>>n)
{
if(m== && t== && n==) break;
read();
solve();
print();
}
}

POJ 2151 Check the difficulty of problems:概率dp【至少】的更多相关文章

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

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

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

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

  3. POJ 2151 Check the difficulty of problems (概率DP)

    题意:ACM比赛中,共M道题,T个队,pij表示第i队解出第j题的概率 ,求每队至少解出一题且冠军队至少解出N道题的概率. 析:概率DP,dp[i][j][k] 表示第 i 个队伍,前 j 个题,解出 ...

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

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

  5. POJ 2151 Check the difficulty of problems

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

  6. poj 2151 Check the difficulty of problems(概率dp)

    poj double 就得交c++,我交G++错了一次 题目:http://poj.org/problem?id=2151 题意:ACM比赛中,共M道题,T个队,pij表示第i队解出第j题的概率 问 ...

  7. POJ 2151 Check the difficulty of problems (概率dp)

    题意:给出m.t.n,接着给出t行m列,表示第i个队伍解决第j题的概率. 现在让你求:每个队伍都至少解出1题,且解出题目最多的队伍至少要解出n道题的概率是多少? 思路:求补集. 即所有队伍都解出题目的 ...

  8. [POJ2151]Check the difficulty of problems (概率dp)

    题目链接:http://poj.org/problem?id=2151 题目大意:有M个题目,T支队伍,第i个队伍做出第j个题目的概率为Pij,问每个队伍都至少做出1个题并且至少有一个队伍做出N题的概 ...

  9. POJ2157 Check the difficulty of problems 概率DP

    http://poj.org/problem?id=2151   题意 :t个队伍m道题,i队写对j题的概率为pij.冠军是解题数超过n的解题数最多的队伍之一,求满足有冠军且其他队伍解题数都大于等于1 ...

随机推荐

  1. AutoCAD如何输入文字

    1 运行文字命令(这里使用单行文字),然后鼠标点击文字的起始点,如图所示   2 鼠标分别向上和向右移动一定距离,表示文字的高度(文字的大小)和文字的旋转角度(一般向右,因为是水平文字)   3 最后 ...

  2. HDU 4927 大数

    题意非常easy: 对于长度为n的数.做n-1遍.生成的新数列: b1=a2-a1   b2=a3-a2  b3=a4-a3 c1=b2-b1   c2=b3-b2 ans=c2-c1 最后推出公式: ...

  3. WPF 基础到企业应用系列5——WPF千年轮回 续前缘

    一.摘要 首先非常高兴这个系列能得到大家的关注和支持,前端时间身体状况不适,所以暂停了更新,对此表示非常抱歉,以后会逐渐加快进度.只是因为这是一个非常长的系列,我也想把它写好,所以以后也会慢慢来,在这 ...

  4. html中图片上传预览的实现

    本地图片预览 第一种方法 <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type& ...

  5. UML类图简明教程

    作者:郭孝星 微博:郭孝星的新浪微博 邮箱:allenwells@163.com 博客:http://blog.csdn.net/allenwells Github:https://github.co ...

  6. ngui 输入事件处理

    NGUI不仅提供了图形接口,还提供了输入事件接口!事件接口是通过UICamera来实现的. Unity3d 为我们提供的原装的input尽管非常方便,但真正跨平台使用时(尤其是跨手机与Pc机时)仍然不 ...

  7. HDU BestCoder Round #1 1002 项目管理

    项目管理 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submi ...

  8. python tkinter module的用法

    tkinter windows下从python3.2版本之后是自动安装的. python3.3之后的引入方式: >>> import _tkinter>>> imp ...

  9. ie63像素bug原因及解决办法不使用hack

    1.浮动元素后边跟不浮动元素时会产生3像素bug 2.解决办法是不要忘记给浮动元素的相邻元素加上浮动.

  10. webStorm 多列编辑

    webStorm可以像Sublime一样使用列编辑,只是区别在于webStorm只可以编辑连续列表. 按住alt键鼠标选择一列,然后输入文字就会编辑多行,这个功能很赞,比较实用(按住ALT键选中之后, ...