poj2151(Check the difficulty of problems)

题目地址:Check the difficulty of problems

题目大意:

在编程比赛中有M个题,T支队伍。要求冠军团队至少做出N道题。

求每对至少做出一道题的同时冠军队至少做出N道题的概率。

解题思路:

概率+DP。首先做的是将题目求的概率转化成:每队均至少做一题的概率P1 减去 每队做题数均在1到N-1之间的概率P2 。


然后求出p1和p2.下面是转到一份网上详解。

代码:

 1 #include <algorithm>
 2 #include <iostream>
 3 #include <sstream>
 4 #include <cstdlib>
 5 #include <cstring>
 6 #include <cstdio>
 7 #include <string>
 8 #include <bitset>
 9 #include <vector>
10 #include <queue>
11 #include <stack>
12 #include <cmath>
13 #include <list>
14 #include <map>
15 #include <set>
16 using namespace std;
17 /***************************************/
18 #define ll long long
19 #define int64 __int64
20 /***************************************/
21 const int INF = 0x7f7f7f7f;
22 const double eps = 1e-8;
23 const double PIE=acos(-1.0);
24 const int dx[]= {0,-1,0,1};
25 const int dy[]= {1,0,-1,0};
26 const int fx[]= {-1,-1,-1,0,0,1,1,1};
27 const int fy[]= {-1,0,1,-1,1,-1,0,1};
28 /***************************************/
29 void openfile()
30 {
31     freopen("data.in","rb",stdin);
32     freopen("data.out","wb",stdout);
33 }
34 /**********************华丽丽的分割线,以上为模板部分*****************/
35 double p[1001][35],dp[1001][35][35],s[1001][35];
36 int main()
37 {
38     int m,t,n;
39     while(scanf("%d%d%d",&m,&t,&n)&&(m+t+n))
40     {
41         memset(p,0,sizeof(p));
42         memset(dp,0,sizeof(dp));
43         memset(s,0,sizeof(s));
44         int i,j,k;
45         double ce=1.0,sum=0;
46         for(i=1;i<=t;i++)
47             for(j=1;j<=m;j++)
48                 scanf("%lf",&p[i][j]);
49         for(i=1;i<=t;i++)
50         {
51             dp[i][0][0]=1.0;
52             for(j=1;j<=m;j++)
53             {
54                 dp[i][j][0]=dp[i][j-1][0]*(1-p[i][j]);
55             }
56             for(j=1;j<=m;j++)
57             {
58                 for(k=1;k<=j;k++)
59                 {
60                     dp[i][j][k]=dp[i][j-1][k]*(1-p[i][j])+dp[i][j-1][k-1]*p[i][j];
61                 }
62             }
63             s[i][0]=dp[i][m][0];
64             for(j=1;j<=m;j++)
65             {
66                 s[i][j]=s[i][j-1]+dp[i][m][j];
67             }
68         }
69         double p1=1.0,p2=1.0;
70         for(i=1;i<=t;i++)
71             p1*=(s[i][m]-s[i][0]);
72         for(i=1;i<=t;i++)
73             p2*=(s[i][n-1]-s[i][0]);
74         printf("%.3lf\n",p1-p2);
75     }
76     return 0;
77 }

poj2151(Check the difficulty of problems)

时间: 2024-11-05 18:44:45

poj2151(Check the difficulty of problems)的相关文章

【POJ2151】Check the difficulty of problems

题意 某场比赛有M道问题,T支队伍,和数字N给出每支队伍解决每道问题的概率. 问这场比赛满足下面两个条件的概率 1.每支队伍至少做出一道题 2.冠军队至少做出N道题. 分析 条件2是不是可以转化为 至少有一支队做出N道及以上道题. 这个题主要是概率,其次才是dp,而且好像不算概率DP. 我们来倒推一下. 设p2为每支队伍做出来的题数都在(1-N-1)的概率.p1为每只队伍至少做出来一道题的概率.那么答案就是p1-p2. 然后我们再来想怎么求p1和p2.设s[i][j]为第i支队伍做出来题数小于等

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)

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 (检查问题的难度)

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

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

POJ 2151:Check the difficulty of problems 概率DP

Check the difficulty of problems 题目连接: http://poj.org/problem?id=2151 题意: 有M (0<M≤30)个人,和T (1<T≤1000)道题目,求所有人都至少做出了一道题且其中有人做出N (0<N≤M)道或N道以上的概率 题解: 求出满足条件1(所有人都至少做出一道题目)的概率,再求出满足条件1且所有人的题数都小于N道的概率,减一下就是答案了 代码 #include<stdio.h> #include<s

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