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] + g[i][j-1][k]*(1-f[i][j])

 1 /*
 2 Problem: 2151        User: bibier
 3 Memory: 5120K        Time: 47MS
 4 Language: G++        Result: Accepted
 5 */
 6
 7 #include <stdio.h>
 8 #include <string.h>
 9 #include <iostream>
10 #include <algorithm>
11 #include <cstdio>
12 #include <cstring>
13 #include <cmath>
14 #include <stack>
15 #include <queue>
16 #include <vector>
17 using namespace std;
18 #define M 0x0f0f0f0f
19 #define min(a,b) (a>b?b:a)
20 #define max(a,b) (a>b?a:b)
21
22
23 float f[1003][33];//f[i][j]第i队做对第j个题的概率
24 float g[1003][33][33];//g[i][j][k]第i队前j个题做对k个题的概率
25
26 //g[i][j][k] = g[i][j-1][k-1]*f[i][j] + g[i][j-1][k]*(1-f[i][j])
27 int main()
28 {
29     int tn,dn,n;
30     int i,j,k;
31     while(scanf("%d %d %d",&tn,&dn,&n)!=EOF)
32     {
33         if(tn==0&&dn==0&&n==0)
34             break;
35         memset(g,0,sizeof(g));
36         memset(f,0,sizeof(f));
37
38         for(i=1; i<=dn; i++)
39             for(j=1; j<=tn; j++)
40                 scanf("%f",&f[i][j]);
41
42         for(i=1; i<=dn; i++)
43         {
44             g[i][1][0]=1-f[i][1];
45             g[i][1][1]=f[i][1];
46         }
47
48         for(i=1; i<=dn; i++)
49             for(j=2; j<=tn; j++)
50                 for(k=0; k<=j; k++)
51                 {
52                     if(k==j)
53                         g[i][j][k] = g[i][j-1][k-1]*f[i][j];
54                     else if(k==0)
55                         g[i][j][k] = g[i][j-1][k]*(1-f[i][j]);
56                     else
57                         g[i][j][k] = g[i][j-1][k-1]*f[i][j] + g[i][j-1][k]*(1-f[i][j]);
58                 }
59         float all=1;
60         for(i=1; i<=dn; i++) //每队至少做对一道题的最终概率
61             all*=(1-g[i][tn][0]);
62
63         float midall=1;
64         for(i=1; i<=dn; i++)
65         {
66             float everyd=0;
67             for(j=1; j<n; j++)
68             {
69                 everyd+=g[i][tn][j];
70             }
71             midall*=everyd;
72         }
73         all-=midall;
74         printf("%.3f\n",all);
75     }
76     return 0;
77 }

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

时间: 2024-10-11 10:02:15

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

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 (概率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(线段树+概率)

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

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)

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

[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

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]

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

题目链接:http://poj.org/problem?id=2151 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 solv

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(