#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define popcount __builtin_popcount using namespace std; typedef long long int ll; typedef pair P; int main() { int r, c; cin>>r>>c; double p[11][11]; int s[11][11]; for(int i=0; i>p[i][j]; for(int i=0; i>s[i][j]; double dp[12][1<<11]={}; dp[0][0]=1; double ans=0; double q[11][1<<11]; for(int i=0; i=4){ que[u]=l; u++; used[l]=1; m^=(1<0){ cnt[x-1]++; if(cnt[x-1]>=4 && !used[x-1]){ que[u]=x-1; u++; used[x-1]=1; m^=(1<<(x-1)); } } if(x=4 && !used[x+1]){ que[u]=x+1; u++; used[x+1]=1; m^=(1<<(x+1)); } } } dp[i+1][m]+=q[i][k]*dp[i][j]; ans+=q[i][k]*dp[i][j]*popcount(m); } } } printf("%.9lf\n", ans); return 0; }