//(◞‸◟) package no309b; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.HashMap; import java.util.InputMismatchException; import java.util.NoSuchElementException; public class Main { public static long stime; public static double solve(int r,int c,double[][] p,int[][] s) { double ans = 0; double[] bef = new double[1< pm = new HashMap(); //m1mの逆変換 long[] m1m = new long[1<=0;j--) { m1m[i] = (m1m[i] << 4) | (i >> j & 1); m2m[i] = (m2m[i] << 4) | ((i >> j & 1) * 0xf); } pm.put(m1m[i], i); bitcount[i] = Integer.bitCount(i); } long[] sm = new long[r]; //知っているときのポイントをlongに詰める for(int i=0;i=0;j--) { sm[i] = (sm[i] << 4) | (4 - s[i][j]); } } HashMap memo = new HashMap(); int[] point = new int[c]; for(int i=0;i> j) & 1) > 0 ? p[i][j] : (1 - p[i][j]); } for(int m1=0;m1<1<> 1; pointm += ~(magic | magic >> 2 | 0xEEEE_EEEE_EEEE_EEEEL); //0を1に // System.out.println(Long.toHexString(pointm)); //メモ化すればここが前計算O(C 5^C)で計算可能? この段階でポイントが1でも0でも変わらないからC 4^Cになる Integer m3 = memo.get(pointm); if (m3 == null) { long pmm = pointm; for(int j=0;j>= 4; } for(int j=0;j= 4) { point[j+1]++; } } for(int j=c-1;j>=1;j--) { if (point[j] >= 4) { point[j-1]++; } } int m32 = 0; for(int j=c-1;j>=0;j--) { m32 <<= 1; if (point[j] >= 4) { m32 |= 1; } } m3 = m32; memo.put(pointm, m3); } now[m3] += bef[m1] * q; ans += bef[m1] * q * bitcount[m3]; } } bef = now; } // System.out.println(memo.size()); return ans; } public static void main(String[] args) { IO io = new IO(); int r = io.nextInt(); int c = io.nextInt(); double[][] p = new double[r][c]; for(int i=0;i Integer.MAX_VALUE) { throw new NumberFormatException(); } return (int) nl; } public char nextChar() { if (!hasNext()) { throw new NoSuchElementException(); } return (char) readByte(); } public double nextDouble() { return Double.parseDouble(next());} public int[] nextIntArray(int n) { int[] a = new int[n]; for(int i=0;i