【POJ】【2151】Check the difficulty of problems

概率DP

  kuangbin总结中的第8题

  一开始题目看错导致想转移方程想错了……想成f[i][j]表示前 i 个队伍中最多的做出来 j 道题的概率……sigh

  看了下题解……其实是对于每个队伍 i 单独考虑做出来 j 道题的概率!!最后再根据情况将t个队伍合并起来……

WA:又忘了POJ上double输出应该用%f了……so sad

 1 //POJ 2151
 2 #include<cmath>
 3 #include<vector>
 4 #include<cstdio>
 5 #include<cstring>
 6 #include<cstdlib>
 7 #include<iostream>
 8 #include<algorithm>
 9 #define rep(i,n) for(int i=0;i<n;++i)
10 #define F(i,j,n) for(int i=j;i<=n;++i)
11 #define D(i,j,n) for(int i=j;i>=n;--i)
12 #define pb push_back
13 using namespace std;
14 int getint(){
15     int v=0,sign=1; char ch=getchar();
16     while(!isdigit(ch)) {if(ch==‘-‘) sign=-1; ch=getchar();}
17     while(isdigit(ch))  {v=v*10+ch-‘0‘; ch=getchar();}
18     return v*sign;
19 }
20 const int N=1010,INF=~0u>>2;
21 /*******************template********************/
22 double p[N][35],f[N][31][31],s[N][31];
23 int main(){
24     int n,m,t;
25     while(scanf("%d%d%d",&m,&t,&n)!=EOF && m){
26         F(i,1,t) F(j,1,m) scanf("%lf",&p[i][j]);
27
28         F(i,1,t){
29             f[i][0][0]=1.0;
30             F(j,1,m)
31                 f[i][j][0]=f[i][j-1][0]*(1-p[i][j]);
32             F(j,1,m) F(k,1,j)
33                 f[i][j][k]=f[i][j-1][k-1]*p[i][j]+f[i][j-1][k]*(1-p[i][j]);
34             s[i][0]=f[i][m][0];
35             F(k,1,m) s[i][k]=s[i][k-1]+f[i][m][k];
36         }
37         double p1=1,p2=1;
38         F(i,1,t){
39             p1*=(1-s[i][0]);
40             p2*=(s[i][n-1]-s[i][0]);
41         }
42         printf("%.3f\n",p1-p2);
43     }
44     return 0;
45 }

时间: 2024-10-27 20:11:05

【POJ】【2151】Check the difficulty of problems的相关文章

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

[POJ 2151]Check the difficulty of problems 明明是道概率dp 训练计划里却赤果果放在了hash+二分里....shenmegui 不过强行把概率dp给整了出来..自己瞎捣鼓居然捣鼓出来了 T支队伍每支队伍都要解M道题 问每只队伍至少解1道并且解答最多的队伍要解N道以上的概率是多少 直接做很难 可以用补集 P(AllTeam >= 1 && MaxTeam >= N) = 1 - P(HasTeam < 1 || AllTeam &

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

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

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