#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; double p[1010][1010][5]; double dp[1010][1010]; int n,m; void fun() { int i,j,k; for(i=n;i>=1;i--) { for(j=m;j>=1;j--) { if(i==n&&j==m) continue; if(p[i][j][0]==1) continue; //dp[i][j]=dp[i][j]*p0+dp[i][j+1]*p1+dp[i+1][j]*p2; dp[i][j]=(2+p[i][j][1]*dp[i][j+1]+p[i][j][2]*dp[i+1][j])/(1-p[i][j][0]); } } } int main() { int i,j,k; int l,r; while(scanf("%d%d",&n,&m)!=EOF) { memset(dp,0,sizeof(dp)); for(i=1;i<=n;i++) { for(j=1;j<=m;j++) { scanf("%lf%lf%lf",&p[i][j][0],&p[i][j][1],&p[i][j][2]); } } fun(); printf("%.3lf ",dp[1][1]); } return 0; }