#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef pair Pii; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define FOR(i, a, b) for (int i = (int)a; i <= (int)b; i++) template void checkmin(T &a, T b) { if (b < a) a = b; } template void checkmax(T &a, T b) { if (b > a) a = b; } const int MaxSize = 11; const int Threshold = 4; int H, W; double Prob[MaxSize][MaxSize]; int Val[MaxSize][MaxSize]; int AtLast[1 << MaxSize * 2]; double dp[1 << MaxSize], nextdp[1 << MaxSize]; void simulate() { int S = 1 << W * 2; int pt[MaxSize]; int who[MaxSize], nextWho[MaxSize]; rep(mask, S) { int num = 0; for (int c = 0; c < W; c++) { pt[c] = 1 + (mask >> c * 2 & 3); if (pt[c] == Threshold) { who[num++] = c; AtLast[mask] += 1 << c; } } while (num > 0) { int nextNum = 0; rep(i, num) { int c = who[i]; if (c - 1 >= 0 && ++pt[c - 1] == Threshold) { nextWho[nextNum++] = c - 1; AtLast[mask] += 1 << c - 1; } if (c + 1 < W && ++pt[c + 1] == Threshold) { nextWho[nextNum++] = c + 1; AtLast[mask] += 1 << c + 1; } } swap(who, nextWho); num = nextNum; } } } void solve() { simulate(); dp[0] = 1; double ans = 0; rep(r, H) { memset(nextdp, 0, sizeof(nextdp)); rep(currMask, 1 << W) { double currMaskProb = 1; rep(c, W) { if (currMask >> c & 1) currMaskProb *= Prob[r][c]; else currMaskProb *= 1 - Prob[r][c]; } rep(prevMask, 1 << W) if (dp[prevMask] > 0) { double p = dp[prevMask] * currMaskProb; int key = 0; rep(c, W) { int pt = Val[r][c] * (currMask >> c & 1); if (r > 0) pt += prevMask >> c & 1; key |= max(0, min(Threshold, pt) - 1) << c * 2; } int nextMask = AtLast[key]; ans += p * __builtin_popcount(nextMask); nextdp[nextMask] += p; } } swap(dp, nextdp); } printf("%.11f\n", ans); } int main() { cin >> H >> W; rep(r, H) rep(c, W) { cin >> Prob[r][c]; Prob[r][c] /= 100.0; } rep(r, H) rep(c, W) { cin >> Val[r][c]; Val[r][c] = Threshold - Val[r][c]; } solve(); return 0; }