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

链接:poj 2151

题意:比赛中有M道题,T个参赛队,pij表示第i队解出第j题的概率,

求每队至少解出一题,且冠军队至少解出N道题的概率

分析:要求每队至少解出一题,且冠军队至少解出N道题的概率

则原来的所求的概率可以转化为:

每队均至少做一题的概率P1 减去 每队做题数均在1到N-1之间的概率P2

设dp[i][j][k]表示第i队在前j道题解出k道题的概率

则dp[i][j][k]=dp[i][j-1][k-1]*pij+dp[i][j-1][k]*(1-pij)

设sum[i][j]为第i队至多解出j道题的概率

则 sum[i][j]=dp[i][M][0]+dp[i][M][1]+...+dp[i][M][j]

sum[i][M]-sum[i][0]为第i队至少解出1道题的概率

sum[i][N-1]-sum[i][0]为第i队解出 [1,N-1]道题的概率

#include<stdio.h>
#include<string.h>
double p[1005][32],dp[32][32],sum[32],p1,p2;
int main()
{
    int t,m,n,i,j,k;
    while(scanf("%d%d%d",&m,&t,&n)!=EOF){
        if(t==0&&m==0&&n==0)
            break;
        for(i=1;i<=t;i++)
            for(j=1;j<=m;j++)
                scanf("%lf",&p[i][j]);
        memset(dp,0,sizeof(dp));
        memset(sum,0,sizeof(sum));
        p1=p2=1.0;
        for(i=1;i<=t;i++){
            dp[0][0]=1.0;
            for(j=1;j<=m;j++){
                dp[j][0]=dp[j-1][0]*(1-p[i][j]);
                for(k=1;k<=j;k++)
                    dp[j][k]=dp[j-1][k]*(1-p[i][j])+dp[j-1][k-1]*p[i][j];
            }
            sum[0]=dp[m][0];
            for(j=1;j<=m;j++)
                sum[j]=sum[j-1]+dp[m][j];
            p1*=(sum[m]-sum[0]);
            p2*=(sum[n-1]-sum[0]);
        }
        printf("%.3lf\n",p1-p2);
    }
    return 0;
}

时间: 2024-10-24 04:30:05

poj 2151 Check the difficulty of problems (dp,概率)的相关文章

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

题意:给出m.t.n,接着给出t行m列,表示第i个队伍解决第j题的概率. 现在让你求:每个队伍都至少解出1题,且解出题目最多的队伍至少要解出n道题的概率是多少? 思路:求补集. 即所有队伍都解出题目的概率,减去所有队伍解出的题数在1~n-1之间的概率 这里关键是如何求出某个队伍解出的题数在1~n-1之间的概率,采用dp的方法: 用p(i,j)表示前i道题能解出j道的概率,有p(i,j)=p(i-1,j)*(1-p(i))+p(i-1,j-1)*p(i)p(i)表示解出第i题的概率. #inclu

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

Language: Default Check the difficulty of problems Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 5419   Accepted: 2384 Description Organizing a programming contest is not an easy job. To avoid making the problems too difficult, the org

POJ 2151 Check the difficulty of problems:概率dp【至少】

题目链接: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(

POJ 2151 Check the difficulty of problems(dp,求概率)

题目大意: 求每个队伍都至少做出一题,并且有人做题数大于等于N的概率. 解题思路: 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]; 用s[i][j]表示第i支队伍作出的题目小于等于j的概率. 则s[i][j] = dp[i][M][0] + dp[i][M][1] + ....... + dp[i][M][j]; p1表

POJ 2151 Check the difficulty of problems (动态规划-概率DP)

Check the difficulty of problems Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4522   Accepted: 1993 Description Organizing a programming contest is not an easy job. To avoid making the problems too difficult, the organizer usually exp

poj 2151 Check the difficulty of problems

dp[i][j][s]表示第i个人,在前j个问题解决了s个问题 dp[i][j][s]=dp[i][j-1][s-1]*p[i][j]+dp[i][j-1][s]*(1-p[i][j]); 1 #include<iostream> 2 #include<string> 3 #include<cstdio> 4 #include<vector> 5 #include<queue> 6 #include<stack> 7 #include

poj 2151 Check the difficulty of problems (检查问题的难度)

poj 2151 Check the difficulty of problems http://poj.org/problem?id=2151 题意:此刻有tn道题目,有dn个队伍,知道每个队伍能答对每个题目的概率,问:冠军至少答对n(1<=n<=tn)道题目,其他队伍至少要答对一道题目的概率 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] +

poj 2151 Check the difficulty of problems(线段树+概率)

Check the difficulty of problems Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4465   Accepted: 1966 Description Organizing a programming contest is not an easy job. To avoid making the problems too difficult, the organizer usually exp

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

Check the difficulty of problems Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4748   Accepted: 2078 Description Organizing a programming contest is not an easy job. To avoid making the problems too difficult, the organizer usually exp