Posted 07/24/2015Updated 07/19/2023 Semprathlon / Simfae Dean ACM-ICPC / Programinga minute read (About 160 words)hdu 3853 LOOPS 递推求期望hdu 3853 LOOPS计算期望,往往是从末状态到初状态倒推的,相见恨晚 123456789101112131415161718192021222324252627282930313233#include<stdio.h>#include<iostream>#include<algorithm>#include<string.h>#include<math.h>using namespace std;const int MAXN=1010;const double eps=1e-5;double dp[MAXN][MAXN];double p1[MAXN][MAXN];double p2[MAXN][MAXN];double p3[MAXN][MAXN];int main(){ int R,C; while(scanf("%d%d",&R,&C)!=EOF) { for(int i=1;i<=R;i++) for(int j=1;j<=C;j++) scanf("%lf%lf%lf",&p1[i][j],&p2[i][j],&p3[i][j]); dp[R][C]=0; for(int i=R;i>=1;i--) for(int j=C;j>=1;j--) { if(i==R&&j==C)continue; if(fabs(1-p1[i][j])<eps)continue; dp[i][j]=p2[i][j]/(1-p1[i][j])*dp[i][j+1]+p3[i][j]/(1-p1[i][j])*dp[i+1][j]+2/(1-p1[i][j]); } printf("%.3lf\n",dp[1][1]); } return 0;}hdu 3853 LOOPS 递推求期望https://devblog.citruxonve.net/posts/8b198553/AuthorSemprathlon / Simfae DeanPosted on07/24/2015Updated on07/19/2023Licensed under#Expect