import java.util.Arrays; import java.util.HashSet; import java.util.LinkedList; import java.util.Scanner; import java.util.Set; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); final int R = sc.nextInt(); final int C = sc.nextInt(); double[][] probs = new double[R][C]; for(int i = 0; i < R; i++){ for(int j = 0; j < C; j++){ probs[i][j] = sc.nextDouble(); } } int[][] shys = new int[R][C]; for(int i = 0; i < R; i++){ for(int j = 0; j < C; j++){ shys[i][j] = sc.nextInt(); } } final int DP_SIZE = 1 << C; double[][] DP = new double[R + 1][DP_SIZE]; //配るDPする. boolean[][] valid_state = new boolean[R + 1][DP_SIZE]; Arrays.fill(DP[0], 0); DP[0][0] = 1.0; valid_state[0][0] = true; for(int r = 0; r < R; r++){ // O(R) for(int prev_raise_bit = 0; prev_raise_bit < DP_SIZE; prev_raise_bit++){ // O(2^C) if(!valid_state[r][prev_raise_bit]){ continue; } for(int curr_known_bit = 0; curr_known_bit < DP_SIZE; curr_known_bit++) { // O(2^C) int[] curr_line = new int[C]; for(int i = 0; i < C; i++){ if((prev_raise_bit & (1 << i)) != 0){ curr_line[i]++; } } LinkedList uppers = new LinkedList(); int curr_raise_bit = 0; for(int i = 0; i < C; i++){ if((curr_known_bit & (1 << i)) == 0){ continue; } curr_line[i] += (4 - shys[r][i]); if(curr_line[i] >= 4){ uppers.add(i); curr_raise_bit |= (1 << i); }; } while(!uppers.isEmpty()){ int pos = uppers.poll(); if(curr_line[pos] < 4){ continue; } // raise_up! if(pos > 0 && (curr_raise_bit & (1 << (pos - 1))) == 0){ if(++curr_line[pos - 1] >= 4){ uppers.add(pos - 1); curr_raise_bit |= (1 << (pos - 1));} } if(pos < C - 1 && (curr_raise_bit & (1 << (pos + 1))) == 0){ if(++curr_line[pos + 1] >= 4){ uppers.add(pos + 1); curr_raise_bit |= (1 << (pos + 1));} } } double curr_prob = 1; for(int i = 0; i < C; i++){ curr_prob *= ((curr_known_bit & (1 << i)) != 0) ? (1.0 - probs[r][i] / 100.0) : (probs[r][i] / 100.0); //System.out.println((100.0) / probs[r][i]); } //System.out.println(Integer.toBinaryString(curr_raise_bit) + " " + Integer.toBinaryString(curr_known_bit) + " " + curr_prob); valid_state[r + 1][curr_raise_bit] |= true; DP[r + 1][curr_raise_bit] += DP[r][prev_raise_bit] * curr_prob; } } } /* for(double[] bits : DP){ System.out.println(Arrays.toString(bits)); } */ double answer = 0; for(int r = 0; r <= R; r++){ for(int bit = 0; bit < DP_SIZE; bit++){ answer += Integer.bitCount(bit) * DP[r][bit]; } } System.out.printf("%.11f\n", answer); } }