poj 2151 概率dp
2015-04-11 09:22
204 查看
注意递推过程中的顺序
题意:
ACM比赛中,共M道题,T个队,pij表示第i队解出第j题的概率
问 每队至少解出一题且冠军队至少解出N道题的概率。
解析:DP
设dp[i][j][k]表示第i个队在前j道题中解出k道的概率
则:
dp[i][j][k]=dp[i][j-1][k-1]*p[j][k]+dp[i][j-1][k]*(1-p[j][k]);
先初始化算出dp[i][0][0]和dp[i][j][0];
设s[i][k]表示第i队做出的题小于等于k的概率
则s[i][k]=dp[i][M][0]+dp[i][M][1]+``````+dp[i][M][k];
则每个队至少做出一道题概率为P1=(1-s[1][0])*(1-s[2][0])*```(1-s[T][0]);
每个队做出的题数都在1~N-1的概率为P2=(s[1][N-1]-s[1][0])*(s[2][N-1]-s[2][0])*```(s[T][N-1]-s[T][0]);
最后的答案就是P1-P2
题意:
ACM比赛中,共M道题,T个队,pij表示第i队解出第j题的概率
问 每队至少解出一题且冠军队至少解出N道题的概率。
解析:DP
设dp[i][j][k]表示第i个队在前j道题中解出k道的概率
则:
dp[i][j][k]=dp[i][j-1][k-1]*p[j][k]+dp[i][j-1][k]*(1-p[j][k]);
先初始化算出dp[i][0][0]和dp[i][j][0];
设s[i][k]表示第i队做出的题小于等于k的概率
则s[i][k]=dp[i][M][0]+dp[i][M][1]+``````+dp[i][M][k];
则每个队至少做出一道题概率为P1=(1-s[1][0])*(1-s[2][0])*```(1-s[T][0]);
每个队做出的题数都在1~N-1的概率为P2=(s[1][N-1]-s[1][0])*(s[2][N-1]-s[2][0])*```(s[T][N-1]-s[T][0]);
最后的答案就是P1-P2
#include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #include<cmath> #include<queue> #include<map> using namespace std; #define MOD 1000000007 const double eps=1e-5; #define cl(a) memset(a,0,sizeof(a)) #define ts printf("*****\n"); const int MAXN=1015; int n,m,tt,t; double p[MAXN][50],s[MAXN][MAXN],dp[MAXN][50][50]; int main() { int i,j,k; #ifndef ONLINE_JUDGE freopen("1.in","r",stdin); #endif while(scanf("%d%d%d",&m,&t,&n)!=EOF) { if(n==0&&m==0&&t==0) break; for(i=1;i<=t;i++) { for(j=1;j<=m;j++) scanf("%lf",&p[i][j]); } for(i=1;i<=t;i++) { dp[i][0][0]=1; for(j=1;j<=m;j++) dp[i][j][0]=dp[i][j-1][0]*(1-p[i][j]); for(j=1;j<=m;j++) for(k=1;k<m;k++) { dp[i][j][k]=dp[i][j-1][k-1]*p[i][j]+dp[i][j-1][k]*(1-p[i][j]); } s[i][0]=dp[i][m][0]; for(int k=1;k<=m;k++)s[i][k]=s[i][k-1]+dp[i][m][k]; } double P1=1; double P2=1; for(int i=1;i<=t;i++) { P1*=(1-s[i][0]); P2*=(s[i][n-1]-s[i][0]); } printf("%.3lf\n",P1-P2); } }
相关文章推荐
- POJ-2151 Check the difficulty of problems (概率dp)
- poj 2151 Check the difficulty of problems 概率dp
- POJ 2151 Check the difficulty of problems(概率dp)
- Check the difficulty of problems - poj 2151 (概率+DP)
- POJ 2151 Check the difficulty of problems (动态规划-概率DP)
- POJ 2151 Check the difficulty of problems(概率dp啊)
- POJ 2151 Check the difficulty of problems (概率dp)
- poj 2151 Check the difficulty of problems 概率dp
- poj-2151 Check the difficulty of problems 概率+DP
- POJ 2151 Check the difficulty of problems(概率DP)
- poj2151之概率DP
- poj 2151 Check the difficulty of problems (概率dp)
- POJ_2151_Check the difficulty of problems_概率DP
- poj 2151 Check the difficulty of problems(概率dp)
- poj_2151 Check the difficulty of problems(概率dp)
- poj 2151 概率DP
- poj 2151 <概率DP>
- POJ 2151 Check the difficulty of problems (概率DP)
- POJ 2151 Check the difficulty of problems(概率DP)
- [ACM] POJ 2151 Check the difficulty of problems (概率+DP)