inputs = lambda:map(int, raw_input().split()) r, c = inputs() raw_input() p = [inputs() + [0] for i in xrange(r)] + [0]*(c+1) raw_input() s = [inputs() + [4] for i in xrange(r)] + [4]*(c+1) dpl = [[0]*(c+1) for i in xrange(r+1)] dpr = [[0]*(c+1) for i in xrange(r+1)] dps = [[0]*(c+1) for i in xrange(r+1)] ans = 0 def f(a, b, c): r = ps[j] if a else 1.-ps[j] r *= rl[j-1] if b else 1.-rl[j-1] r *= rr[j+1] if c else 1.-rr[j+1] return r for i in xrange(r): ps = dps[i-1] rl = dpl[i] rr = dpr[i] rs = dps[i] si = s[i] pi = p[i] # left for j in xrange(c): if si[j]==0: rl[j] = pi[j]/100.0 elif si[j]==1: rl[j] = pi[j]*(1. - (1.-rl[j-1])*(1.-ps[j]))/100.0 elif si[j]==2: rl[j] = pi[j]*rl[j-1]*ps[j]/100.0 else: # 3 or 4 rl[j] = 0 # right for j in xrange(c-1,-1,-1): if si[j]==0: rr[j] = pi[j]/100.0 elif si[j]==1: rr[j] = pi[j]*(1. - (1.-rr[j+1])*(1.-ps[j]))/100.0 elif si[j]==2: rr[j] = pi[j]*rr[j+1]*ps[j]/100.0 else: # 3 or 4 rr[j] = 0 # sum for j in xrange(c): if si[j]==0: rs[j] = pi[j]/100.0 elif si[j]==1: rs[j] = pi[j]*(1.-f(0,0,0))/100.0 elif si[j]==2: rs[j] = pi[j]*(f(1,1,1)+f(1,1,0)+f(1,0,1)+f(0,1,1))/100.0 elif si[j]==3: rs[j] = pi[j]*f(1,1,1)/100.0 else: # 4 rs[j] = 0 ans += rs[j] print ans