/* -*- coding: utf-8 -*- * * 1560.cc: No.1560 majority x majority - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 5000; const int MAX_M = 12; const int MBITS = 1 << MAX_M; /* typedef */ typedef long long ll; /* global variables */ int ss[MAX_N][MAX_M]; bool fs[MAX_N][MBITS]; ll dp[MBITS]; /* subroutines */ bool approved(int n, int bits, int bi) { int cnt = 0, sup = 0; for (int i = 0; i < n; i++) { if (fs[i][bits]) cnt++; if (fs[i][bits | bi]) sup++; } return (sup * 2 >= cnt); } /* main */ int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) scanf("%d", ss[i] + j); int mbits = 1 << m; for (int i = 0; i < n; i++) { fs[i][0] = true; for (int bits = 1, msb = 1, msi = 0; bits < mbits; bits++) { if ((msb << 1) <= bits) msb <<= 1, msi++; fs[i][bits] = fs[i][bits ^ msb] && ss[i][msi]; } } dp[0] = 1; for (int bits = 0; bits < mbits; bits++) for (int i = 0, bi = 1; i < m; i++, bi <<= 1) if (! (bits & bi) && approved(n, bits, bi)) dp[bits | bi] += dp[bits]; printf("%lld\n", dp[mbits - 1]); return 0; }