#include #include #include #include //#include #include #include #include #include #include //#include #include #include #include //#include #include #include //#include #include #include #include #include const int dx[] = {1, 0, -1, 0}; const int dy[] = {0, 1, 0, -1}; using namespace std; typedef long long ll; typedef vector vi; typedef vector vll; typedef pair pii; const int MAX = 11; int P[MAX][MAX], S[MAX][MAX]; double dp[MAX][MAX]; int cnt[MAX]; int main() { int R, C; cin >> R >> C; for (int i = 0; i < R; i++) for (int j = 0; j < C; j++) cin >> P[i][j]; for (int i = 0; i < R; i++) for (int j = 0; j < C; j++) cin >> S[i][j]; // 最初の行 for (int s = 0; s < (1<>i)&1) prob *= P[0][i]/100.; else prob *= (100-P[0][i])/100.; } if (prob == 0) continue; queue que; memset(cnt, 0, sizeof(cnt)); for (int i = 0; i < C; i++) { if ((s>>i)&1) cnt[i] = 4-S[0][i]; if (cnt[i] >= 4) que.push(i); } while (!que.empty()) { int now = que.front(); que.pop(); if (now-1 >= 0) { cnt[now-1]++; if (cnt[now-1] == 4) que.push(now-1); } if (now+1 < C) { cnt[now+1]++; if (cnt[now+1] == 4) que.push(now+1); } } for (int i = 0; i < C; i++) { if (cnt[i] >= 4) dp[0][i] += prob; } } // 以降の行 for (int i = 1; i < R; i++) { for (int s = 0; s < (1<<(2*C)); s++) { double prob = 1; for (int j = 0; j < C; j++) { if ((s>>j)&1) prob *= dp[i-1][j]; else prob *= 1-dp[i-1][j]; } for (int j = 0; j < C; j++) { if ((s>>(j+C))&1) prob *= P[i][j]/100.; else prob *= (100-P[i][j])/100.; } if (prob == 0) continue; queue que; memset(cnt, 0, sizeof(cnt)); for (int j = 0; j < C; j++) { if ((s>>(j+C))&1) cnt[j] = 4-S[i][j]; if ((s>>j)&1) cnt[j]++; if (cnt[j] >= 4) que.push(i); } while (!que.empty()) { int now = que.front(); que.pop(); if (now-1 >= 0) { cnt[now-1]++; if (cnt[now-1] == 4) que.push(now-1); } if (now+1 < 0) { cnt[now+1]++; if (cnt[now+1] == 4) que.push(now+1); } } for (int j= 0; j < C; j++) { if (cnt[j] >= 4) dp[i][j] += prob; } } } double ans = 0; for (int i = 0; i < R; i++) for (int j = 0; j < C; j++) ans += dp[i][j]; printf("%.10lf\n", ans); return 0; }