• (POJ 2151)Check the difficulty of problems(概率DP+容斥)


    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



    比较简单的一道概率dp,然而还是没能自己想出来(现在一丢丢罪恶感都没。。。)
    要求的概率=P(所有队伍都不挂机)-P(所有队伍的过题数都在[1,n-1]之间)
    在DP的时候开一个三维数组:dp[i][j][k]表示第i支队伍在前j题中通过了k道题,这样在最后可以看dp[i][m][k]来得到每个队伍过某题数的概率。递推方程很好得出:dp[i][j][k]=dp[i][j-1][k]*(1-p[i][j])+dp[i][j-1][k-1]*p[i][j];
    注意:①k=0时是特殊情况,dp值要单独计算!
       ②提交时看好自己的printf格式,如果是G++需要将double型用%.3f输出,C++用%lf输出。
    #include<iostream>
    #include<cstdio>
    #include<vector>
    #include<set>
    #include<map>
    #include<string.h>
    #include<cmath>
    #include<algorithm>
    #include<queue>
    #include<stack>
    #define LL long long
    #define mod 1000000007
    #define inf 0x3f3f3f3f
    
    using namespace std;
    
    
    double a[1100][55];
    double dp[1100][55][55];
    int main()
    {
        int m,t,n;
        while(~scanf("%d%d%d",&m,&t,&n))
        {
            if(t==0&&m==0&&n==0)
                break;
            memset(a,0,sizeof(a));
            memset(dp,0,sizeof(dp));
            for(int i=1;i<=t;i++)
                for(int j=1;j<=m;j++)
                    scanf("%lf",&a[i][j]);
    
            for(int i=1;i<=t;i++)
            {
                dp[i][1][0]=1-a[i][1];
                dp[i][1][1]=a[i][1];
            }
            for(int i=1;i<=t;i++)
                for(int j=2;j<=m;j++)
                    for(int k=0;k<=j;k++)
                    {
                        if(k==0)
                            dp[i][j][k]=dp[i][j-1][k]*(1-a[i][j]);
                        else
                            dp[i][j][k]=dp[i][j-1][k-1]*a[i][j]+dp[i][j-1][k]*(1-a[i][j]);
                    }
            double sum=1;
            for(int i=1;i<=t;i++)
                sum*=(1-dp[i][m][0]);
            double ans=1;
            for(int i=1;i<=t;i++)
            {
                double tem=0;
                for(int j=1;j<=n-1;j++)
                    tem+=dp[i][m][j];
                ans*=tem;
            }
    
            printf("%.3lf
    ",sum-ans);
        }
        return 0;
    }
     
    此地非逐弃者之王座,彼方乃行愿者之归所。无限清澈,星界银波。
  • 相关阅读:
    MySQL数据库有哪些安全相关的参数需要修改?
    Python PEP-8编码风格指南中文版
    linux系统/var/log目录下的信息详解
    mcelog用法详解
    timeout 命令
    x86服务器MCE(Machine Check Exception)问题
    IPv6简介
    MySQL innodb统计信息
    memory 监控 mysql vs percona vs maria
    oracle 压力测试工具benchmarksql
  • 原文地址:https://www.cnblogs.com/brotherHaiNo1/p/8419731.html
Copyright © 2020-2023  润新知