HDU3853(期望)

题目很水了,但是原地打转的点……虽然不难想到这个坑,但是从数学的角度来讲期望不应该算正无穷嘛……为什么算0啊?

 

 1 const int maxn = 1e3 + 5;
 2 const db eps = 1e-5;
 3 int R, C;
 4 struct gird {
 5     db ori, right, down;
 6 }p[maxn][maxn];
 7 db E[maxn][maxn];
 8 
 9 int main() {
10     while (scanf("%d %d", &R, &C) != EOF) {
11         rep(i, 1, R) {
12             rep(j, 1, C) {
13                 scanf("%lf %lf %lf", &p[i][j].ori, &p[i][j].right, &p[i][j].down);
14                 E[i][j] = 0;
15             }
16         }
17         irep(i, R, 1) {
18             irep(j, C, 1) {
19                 if (i == R && j == C)    continue;
20                 if (fabs(1 - p[i][j].ori) < eps)    continue;
21                 if (i < R)    E[i][j] += E[i + 1][j] * p[i][j].down;
22                 if (j < C)    E[i][j] += E[i][j + 1] * p[i][j].right;
23                 E[i][j] += 2;
24                 E[i][j] /= (1 - p[i][j].ori);
25             }
26         }
27         printf("%.3lf\n", E[1][1]);
28     }
29     return 0;
30 }

 

posted @ 2019-03-16 21:00  AlphaWA  阅读(300)  评论(1编辑  收藏  举报