题意:迷宫是一个R*C的布局,每个格子中给出停留在原地,往右走一个,往下走一格的概率,起点在(1,1),终点在(R,C),每走一格消耗两点能量,求出最后所需要的能量期望
#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstring>
typedef long long ll;
const int inf=0x3f3f3f3f;
#define For(i,a,b) for(int i=a;i<=b;i++)
#define FFor(i,a,b) for(int i=a;i>=b;i--)
template <class T> inline T min(T a,T b,T c)
{
return min(min(a,b),c);
}
template <class T> inline T max(T a,T b,T c)
{
return max(max(a,b),c);
}
template <class T> inline T min(T a,T b,T c,T d)
{
return min(min(a,b),min(c,d));
}
template <class T> inline T max(T a,T b,T c,T d)
{
return max(max(a,b),max(c,d));
}
using namespace std;
const int N=1e3+;
const double eps=1e-;
//***********name**************
double f[N][N];
int R,C;
double p0[N][N],p1[N][N],p2[N][N]; //***********function********** //******************************
int main()
{
// freopen("test.txt","r",stdin);
while(~scanf("%d%d",&R,&C)){
memset(f,,sizeof(f));
For(i,,R)
For(j,,C)
scanf("%lf%lf%lf",&p0[i][j],&p1[i][j+],&p2[i+][j]);
f[R][C]=;
FFor(i,R,)
FFor(j,C,)
{
if(i==R&&j==C)continue;
if(fabs(p0[i][j]-)<=eps)continue;
f[i][j]=(f[i][j+]*p1[i][j+]+f[i+][j]*p2[i+][j]+)/(-p0[i][j]);
}
printf("%.3f\n",f[][]);
} return ;
}