#include"iostream" #include"algorithm" #include"cstring" #include"cstdio" #include"cmath" #include"vector" #include"map" #include"set" #include"queue" usingnamespace std; #define MAXN 1000006 //#define int long long #define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i) #define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i) #define pii pair<int,int> #define fi first #define se second #define mp make_pair #define pb push_back #define eb emplace_back #define vi vector<int> #define all(x) (x).begin() , (x).end() #define mem( a ) memset( a , 0 , sizeof a ) typedeflonglong ll;
constint inf = 1e9;
int n , m; int A[123][123]; int dp[2][1620];
classRandomPaintingOnABoard { public: doubleexpectedSteps( vector<string> str ){ n = str.size() , m = str[0].size(); int tot = 0; if( n < m ) { rep( i , 0 , n - 1 ) rep( j , 0 , m - 1 ) A[i][j] = str[i][j] - '0' , tot += A[i][j]; } else { swap( n , m ); rep( i , 0 , n - 1 ) rep( j , 0 , m - 1 ) A[i][j] = str[j][i] - '0' , tot += A[i][j]; } double res = 0; for( int i = 0 ; i < ( 1 << n ) ; ++ i ) { int s = 0 , cur = 0; for( int j = 0 ; j < n ; ++ j ) if( i & ( 1 << j ) ) { cur ^= 1; for( int k = 0 ; k < m ; ++k ) s += A[j][k]; } mem( dp ); dp[cur][s] = 1; for( int j = 0 ; j < m ; ++ j ) { int sl = 0; for( int k = 0 ; k < n ; ++ k ) if( ~i & ( 1 << k ) ) sl += A[k][j]; for( int k = tot ; k >= sl ; -- k ) { int t0 = dp[0][k - sl] , t1 = dp[1][k - sl]; dp[0][k] += t1 , dp[1][k] += t0; } } for( int j = 1 ; j <= tot ; ++ j ) res += ( dp[1][j] - dp[0][j] ) * tot * 1. / j; } return res; } } F ;
//int main() { // vector<string> in {"10", "01"}; // cout << F.expectedSteps( in ); //}