概率dp水题
#include <CSTDIO>
#include <STRING.H>
#include <MATH.H>
// hdu 3853
const int MAXN = 1005;
const double _inf = 1e-5;
int r, c;
double p1[MAXN][MAXN], p2[MAXN][MAXN], p3[MAXN][MAXN];
double dp[MAXN][MAXN];
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif
int i, j;
while (scanf("%d%d", &r, &c) != EOF)
{
for (i = 1; i<= r; ++i)
{
for (j = 1; j<= c; ++j)
{
scanf("%lf%lf%lf", &p1[i][j], &p2[i][j], &p3[i][j]);
}
}
for (i = r; i>0; --i)
{
for (j = c; j> 0; --j)
{
if ( 1 - p1[i][j] < _inf)
dp[i][j] = 0.0;
else
dp[i][j] = (2 + p2[i][j]*dp[i][j+1] + p3[i][j]*dp[i+1][j])/(1 - p1[i][j]);
}
}
printf("%.3lf\n", dp[1][1]);
}
return 0;
}