intgetsta() { int s = 0; for (int i = 1; i <= tot; ++ i) s = (s << len[i]) | ((1 << (len[i] - 1)) - 1); return s; }
voiddfs(int rem, int st) { if (rem == 0) { LL cur = 0; for (int i = 0; i < (1 << n); ++ i) if ((popcount(i) ^ n) & 1) cur -= tmp[tot][i]; else cur += tmp[tot][i]; // for (int i = 1; i <= tot; ++ i) std::cout << len[i] << ' '; // std::cout << ": " << cur << '\n'; do ans[getsta()] = cur; while (std::next_permutation(len + 1, len + tot + 1)); return; } if (rem < st) return; ++ tot; for (int i = st; i <= rem; ++ i) { len[tot] = i; for (int s = 0; s < (1 << n); ++ s) tmp[tot][s] = tmp[tot - 1][s] * f[i][s]; dfs(rem - i, i); } tot --; }
intmain() { std::cin >> n; for (int i = 0; i < n; ++ i) { staticchar s[N]; scanf("%s", s); for (int j = 0; j < n; ++ j) a[i][j] = s[j] & 1; } for (int i = 0; i < n; ++ i) dp[1 << i][i] = 1; for (int s = 1; s < (1 << n); ++ s) for (int i = 0; i < n; ++ i) if (dp[s][i]) for (int nxt = 0; nxt < n; ++ nxt) if (a[i][nxt] && (~s >> nxt & 1)) dp[s | (1 << nxt)][nxt] += dp[s][i]; for (int s = 0; s < (1 << n); ++ s) for (int i = 0; i < n; ++ i) f[popcount(s)][s] += dp[s][i]; f[0][0] ++; // for (int i = 0; i <= n; ++ i, std::cout << '\n') // for (int s = 0; s < (1 << n); ++ s) std::cout << f[i][s] << ' '; for (int i = 0; i <= n; ++ i) for (int bit = 0; bit < n; ++ bit) for (int j = 0; j < (1 << n); ++ j) if (j >> bit & 1) f[i][j] += f[i][j ^ (1 << bit)]; for (int s = 0; s < (1 << n); ++ s) tmp[0][s] = 1; dfs(n, 1); for (int bit = 0; bit < n - 1; ++ bit) for (int j = 0; j < (1 << (n - 1)); ++ j) if (j >> bit & 1) ans[j ^ (1 << bit)] -= ans[j]; for (int s = 0; s < (1 << (n - 1)); ++ s) std::cout << ans[s] << ' '; std::cout << '\n'; return0; }