import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintStream; import java.io.PrintWriter; import java.util.ArrayDeque; import java.util.Arrays; import java.util.Iterator; import java.util.Queue; public class Main_yukicoder309 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); Printer pr = new Printer(System.out); int r = sc.nextInt(); int c = sc.nextInt(); int[][] p = new int[r][c]; int[][] s = new int[r][c]; for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { String tmp; for (tmp = sc.next(); tmp.equals(""); tmp = sc.next()) { } p[i][j] = Integer.parseInt(tmp); } } for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { String tmp; for (tmp = sc.next(); tmp.equals(""); tmp = sc.next()) { } s[i][j] = Integer.parseInt(tmp); } } int n = 0x1 << c; // double[][][] ptmp = new double[r + 1][c][n]; /* for (int i = 1; i <= r; i++) { for (int k = 0; k < n; k++) { int[] po = new int[c]; boolean[] used = new boolean[c]; Queue q = new ArrayDeque(); for (int l = 0; l < c; l++) { if (i != 1 && (k & 0x1 << l) != 0) { po[l] = 1; } else { po[l] = 0; } if (po[l] + 4 - s[i - 1][l] >= 4) { ptmp[i][l][k] = (double)p[i - 1][l] / 100; used[l] = true; q.add(l); } } while (!q.isEmpty()) { int e = q.remove(); if (e - 1 >= 0) { po[e - 1]++; if (!used[e - 1] && po[e - 1] + 4 - s[i - 1][e - 1] >= 4) { ptmp[i][e - 1][k] = (double)p[i - 1][e - 1] / 100; used[e - 1] = true; q.add(e - 1); } } if (e + 1 < c) { po[e + 1]++; if (!used[e + 1] && po[e + 1] + 4 - s[i - 1][e + 1] >= 4) { ptmp[i][e + 1][k] = (double)p[i - 1][e + 1] / 100; used[e + 1] = true; q.add(e + 1); } } } } } */ double[][] dp = new double[r + 1][n]; double dtmp = 1; for (int i = 0; i < c; i++) { dtmp /= 2; } Arrays.fill(dp[0], dtmp); for (int i = 1; i <= r; i++) { for (int j = 0; j < n; j++) { for (int k = 0; k < n; k++) { if (dp[i - 1][k] == 0) { continue; } int[] po = new int[c]; boolean[] used = new boolean[c]; Queue q = new ArrayDeque(); double[] ptmp3 = new double[c]; for (int l = 0; l < c; l++) { if (i != 1 && (k & 0x1 << l) != 0) { po[l] = 1; } else { po[l] = 0; } if (po[l] + 4 - s[i - 1][l] >= 4) { // ptmp[i][l][k] = (double)p[i - 1][l] / 100; ptmp3[l] = (double)p[i - 1][l] / 100; used[l] = true; q.add(l); } } while (!q.isEmpty()) { int e = q.remove(); if ((j & 0x1 << e) == 0) { continue; } if (e - 1 >= 0) { po[e - 1]++; if (!used[e - 1] && po[e - 1] + 4 - s[i - 1][e - 1] >= 4) { // ptmp[i][e - 1][k] = (double)p[i - 1][e - 1] / 100; ptmp3[e - 1] = (double)p[i - 1][e - 1] / 100; used[e - 1] = true; q.add(e - 1); } } if (e + 1 < c) { po[e + 1]++; if (!used[e + 1] && po[e + 1] + 4 - s[i - 1][e + 1] >= 4) { // ptmp[i][e + 1][k] = (double)p[i - 1][e + 1] / 100; ptmp3[e + 1] = (double)p[i - 1][e + 1] / 100; used[e + 1] = true; q.add(e + 1); } } } double ptmp2 = 1.0; for (int l = 0; l < c && ptmp2 != 0; l++) { if ((j & 0x1 << l) != 0) { // ptmp2 *= ptmp[i][l][k]; ptmp2 *= ptmp3[l]; } else { // ptmp2 *= (1.0 - ptmp[i][l][k]); ptmp2 *= (1.0 - ptmp3[l]); } } dp[i][j] += ptmp2 * dp[i - 1][k]; } } } double ret = 0; for (int i = 1; i <= r; i++) { for (int j = 0; j < n; j++) { ret += dp[i][j] * Integer.bitCount(j); } } pr.printf("%.14f\n", ret); pr.close(); sc.close(); } @SuppressWarnings("unused") private static class Scanner { BufferedReader br; Iterator it; Scanner (InputStream in) { br = new BufferedReader(new InputStreamReader(in)); } String next() throws RuntimeException { try { if (it == null || !it.hasNext()) { it = Arrays.asList(br.readLine().split(" ")).iterator(); } return it.next(); } catch (IOException e) { throw new IllegalStateException(); } } int nextInt() throws RuntimeException { return Integer.parseInt(next()); } long nextLong() throws RuntimeException { return Long.parseLong(next()); } float nextFloat() throws RuntimeException { return Float.parseFloat(next()); } double nextDouble() throws RuntimeException { return Double.parseDouble(next()); } void close() { try { br.close(); } catch (IOException e) { // throw new IllegalStateException(); } } } private static class Printer extends PrintWriter { Printer(PrintStream out) { super(out); } } }