POJ 2151 Check the difficulty of problems (概率DP)
2015-05-23 11:24
351 查看
问题的解等于(所有队都做出至少一题的概率 - 所有队做题数都在1到N-1之间的概率)
设计DP状态时,因为DP过程中要记录哪些题做过了很难,一般来说要把DP的过程设计成有方向的,比如有一维表示前i个XX这种。
dp[i][j][k]表示第i队前j题做出k个的概率,dp方程就是dp[i][j][k]=dp[i][j-1][k-1]*acr[i][j]+dp[i][j-1][k]*(1-acr[i][j])
初始化dp[i][0][0]为1,dp[i][j][0]都设为相应情况所有题全错的概率。
代码:
设计DP状态时,因为DP过程中要记录哪些题做过了很难,一般来说要把DP的过程设计成有方向的,比如有一维表示前i个XX这种。
dp[i][j][k]表示第i队前j题做出k个的概率,dp方程就是dp[i][j][k]=dp[i][j-1][k-1]*acr[i][j]+dp[i][j-1][k]*(1-acr[i][j])
初始化dp[i][0][0]为1,dp[i][j][0]都设为相应情况所有题全错的概率。
代码:
#include <iostream> #include <cstdio> #include <cstring> using namespace std; #define LL long long double dp[1005][35][35]; double acr[1005][35]; int M,T,N; int main(){ while(~scanf("%d%d%d",&M,&T,&N)){ if(!M&&!T&&!N) break; for(int i=0;i<T;i++){ for(int j=1;j<=M;j++){ scanf("%lf",&acr[i][j]); } } for(int i=0;i<T;i++){ dp[i][0][0]=1; for(int j=1;j<=M;j++){ dp[i][j][0]=dp[i][j-1][0]*(1-acr[i][j]); } } for(int i=0;i<T;i++){ for(int j=1;j<=M;j++){ for(int k=1;k<=j;k++){ dp[i][j][k]=dp[i][j-1][k-1]*acr[i][j]+dp[i][j-1][k]*(1-acr[i][j]); } } } double tot=1; double sub=1; for(int i=0;i<T;i++){ double cur=0; for(int j=1;j<=M;j++){ cur+=dp[i][M][j]; } tot*=cur; cur=0; for(int j=1;j<N;j++){ cur+=dp[i][M][j]; } sub*=cur; } printf("%.3f\n",tot-sub); } return 0; }
相关文章推荐
- 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]
- [ACM] 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)
- 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)
- [ACM] POJ 2151 Check the difficulty of problems (概率+DP)
- poj 2151 Check the difficulty of problems 概率dp