POJ 2151 概率DP
2016-09-29 10:19
281 查看
思路:
f[i][j][k]表示i所学校 前j题 解出了k道
初始化f[i][0][0]和f[i][1][0]
f[i][j][k]=f[i][j-1][k-1]a[i][j]+f[i][j-1][k](1-a[i][j]);
这个时候f[i]
[k]表示第i所学校做出k道题的概率
我们可以维护一个
sum[i]表示第i所学校做出1<=x<=n道题的概率
kth[i]表示第i所学校做出1<=x< k道题的概率
最后把所有的sum[i]乘起来减所有kth[i]乘起来就是最后的解了
f[i][j][k]表示i所学校 前j题 解出了k道
初始化f[i][0][0]和f[i][1][0]
f[i][j][k]=f[i][j-1][k-1]a[i][j]+f[i][j-1][k](1-a[i][j]);
这个时候f[i]
[k]表示第i所学校做出k道题的概率
我们可以维护一个
sum[i]表示第i所学校做出1<=x<=n道题的概率
kth[i]表示第i所学校做出1<=x< k道题的概率
最后把所有的sum[i]乘起来减所有kth[i]乘起来就是最后的解了
//By SiriusRen #include <cstdio> #include <cstring> #include <algorithm> using namespace std; int n,m,K; double a[1005][55],f[1005][55][55],fst[1005],kth[1005],mulfst,mulkth; //f[i][j][k]表示i所学校 前j题 解出了k道 int main(){ while(scanf("%d%d%d",&n,&m,&K)&&(n||m||K)){ memset(fst,0,sizeof(fst)),memset(kth,0,sizeof(kth)),mulfst=mulkth=1; for(int i=1;i<=m;i++){ for(int j=1;j<=n;j++){ scanf("%lf",&a[i][j]); } } for(int i=1;i<=m;i++){ f[i][0][0]=1,f[i][1][0]=1-a[i][1]; for(int j=2;j<=n;j++){ f[i][j][0]=f[i][j-1][0]*(1-a[i][j]); } } for(int i=1;i<=m;i++){ for(int j=1;j<=n;j++){ for(int k=1;k<=j;k++){ f[i][j][k]=f[i][j-1][k-1]*a[i][j]+f[i][j-1][k]*(1-a[i][j]); } } } for(int i=1;i<=m;i++){ for(int j=1;j<=n;j++){ fst[i]+=f[i] [j]; if(j<K)kth[i]+=f[i] [j]; } mulfst*=fst[i];mulkth*=kth[i]; } printf("%.3lf\n",mulfst-mulkth); } }
相关文章推荐
- 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 概率dp
- poj2151之概率DP
- 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 概率DP
- POJ 2151 概率DP
- poj 2151 概率dp
- 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入门