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<algorithm>
 8 #include<cstring>
 9 #include<stdlib.h>
10 #include<cmath>
11 using namespace std;
12 #define pb push_back
13 double dp[1010][35][35],p[1010][35];
14 int main(){
15     int n,m,k;
16     while(cin>>n>>m>>k&&(n+m+k)){
17         for(int i=1;i<=m;i++)
18             for(int j=1;j<=n;j++)
19             scanf("%lf",&p[i][j]);
20         memset(dp,0,sizeof(dp));
21         for(int i=1;i<=m;i++)
22             dp[i][0][0]=1;
23         for(int i=1;i<=m;i++){
24             for(int j=1;j<=n;j++){
25                  dp[i][j][0]=dp[i][j-1][0]*(1-p[i][j]);
26                  for(int s=1;s<=j;s++)
27                  dp[i][j][s]=dp[i][j-1][s-1]*p[i][j]+dp[i][j-1][s]*(1-p[i][j]);
28             }
29         }
30         double tmp=1,ko=1;
31         for(int i=1;i<=m;i++)
32         {
33             double tt=0;
34             for(int j=1;j<=n;j++)
35             tt+=dp[i][n][j];
36             ko*=tt;
37         }
38         for(int i=1;i<=m;i++)
39         {
40             double sum=0;
41             for(int j=1;j<k;j++)
42                 sum+=dp[i][n][j];
43             tmp*=sum;
44         }
45         printf("%.3f\n",ko-tmp);
46     }
47 }

poj 2151 Check the difficulty of problems,布布扣,bubuko.com

时间: 2024-10-24 13:40:28

poj 2151 Check the difficulty of problems的相关文章

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

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

[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(