#include using namespace std; #define rep(i,n) for(int i=0;i<(n);++i) #define loop for(;;) #define trace(var) cerr<<">>> "<<#var<<" = "<; template inline ostream& operator<<(ostream&os, pair p) { return os << '(' << p.first << ", " << p.second << ')'; } template inline ostream& operator<<(ostream&os, tuple t) { return os << '(' << get<0>(t) << ", " << get<1>(t) << ", " << get<2>(t) << ')'; } template inline ostream& operator<<(ostream&os, set v) { os << "(set"; for (T item: v) os << ' ' << item; os << ")"; return os; } template inline ostream& operator<<(ostream&os, vector v) { if (v.size() == 0) { return os << "(empty)"; } os << v[0]; for (int i=1, len=v.size(); i inline istream& operator>>(istream&is, vector&v) { rep (i, v.size()) is >> v[i]; return is; } using vi = vector; using vvi = vector; using vd = vector; using vvd = vector; using vb = vector; int main() { cerr << fixed << setprecision(5); int h, w; cin >> h >> w; vector pt(5, vvd(h, vd(w,0))); // pt[k][i][j] = Pr [point(i,j) == k] vector qt(5, vvd(h, vd(w,0))); { vvi p(h, vi(w, 0)); vvi s(h, vi(w, 0)); rep (i, h) rep (j, w) cin >> p[i][j]; rep (i, h) rep (j, w) cin >> s[i][j]; rep (i, h) rep (j, w) { pt[4-s[i][j]][i][j] = p[i][j] / 100.0; pt[0][i][j] = (100 - p[i][j]) / 100.0; qt[4-s[i][j]][i][j] = p[i][j] / 100.0; qt[0][i][j] = (100 - p[i][j]) / 100.0; } } stack> s; rep (i, h) rep (j, w) { s.push({ i, j }); } vi dx = { 0, -1, 0 }; vi dy = {-1, 0, 1 }; while (not s.empty()) { int i = s.top().first; int j = s.top().second; s.pop(); if (i < 0 or j < 0 or i>=h or j>=w) continue; vd q(4, 0); // q[n] == n人いる確率 q[0] = 1.0; rep (t, 3) { int i2 = i + dx[t]; int j2 = j + dy[t]; if (i2 < 0 or i2 >= h or j2 < 0 or j2 >= w) continue; { double p = qt[4][i2][j2]; q[3] += q[2] * p; q[2] = q[2] * (1-p) + q[1] * p; q[1] = q[1] * (1-p) + q[0] * p; q[0] *= (1-p); } } double memo = qt[4][i][j]; rep (k, 5) qt[k][i][j] = 0; rep (k, 5) { rep (t, 4) { int k2 = k + t; k2 = min(k2, 4); qt[k2][i][j] += pt[k][i][j] * q[t]; } } if (qt[4][i][j] > memo) { s.push({ i+1, j }); s.push({ i, j-1 }); s.push({ i, j+1 }); } } double ans = 0; rep (i, h) rep (j, w) ans += qt[4][i][j]; cout << ans << endl; return 0; }