#include using namespace std; typedef signed long long ll; #undef _P #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x>(x))&1) + ((stand>>(x+2))&1) >= ((mask>>(2*x))&3)) stand |= 1<<(1+x); } stand>>=1; } FOR(mask,1<1e-12) { int curmask=0; FOR(x,W) { r = 4-S[y][x]+((up>>x)&1); r = max(0,min(4-r,3)); curmask |= r<<(2*x); } FOR(cur,1<1e-12) { int hand2=hand; FOR(j,2) FOR(i,W) { x=(j)?i:(W-1-i); if(cur&(1<=4) hand2 |= 1<<(x+1); } } hand2 >>=1; ret += pat*dp[y][up]*__builtin_popcount(hand2); dp[y+1][hand2] += pat*dp[y][up]; } } } return ret; } void solve() { int i,j,k,l,r,x,y; string s; cin>>H>>W; FOR(y,H) FOR(x,W) cin>>r, P[y][x] = r/100.0; FOR(y,H) FOR(x,W) cin>>S[y][x]; _P("%.12lf\n",fast()); //_P("%.12lf\n",slow()); } int main(int argc,char** argv){ string s;int i; if(argc==1) ios::sync_with_stdio(false); FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin); solve(); return 0; }