#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include // #include "utiltime.hpp" using namespace std; typedef long long int ll; typedef vector vi; typedef vector> vvi; typedef pair P; typedef pair Pll; typedef vector vll; typedef vector> vvll; typedef complex cdouble; const int INFL = (int)1e9; const ll INFLL = (ll)1e18; const double INFD = numeric_limits::infinity(); const double PI = 3.14159265358979323846; #define Loop(i, n) for(int i = 0; i < (int)n; i++) #define Loopll(i, n) for(ll i = 0; i < (ll)n; i++) #define Loop1(i, n) for(int i = 1; i <= (int)n; i++) #define Loopll1(i, n) for(ll i = 1; i <= (ll)n; i++) #define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--) #define Looprll(i, n) for(ll i = (ll)n - 1; i >= 0; i--) #define Loopr1(i, n) for(int i = (int)n; i >= 1; i--) #define Looprll1(i, n) for(ll i = (ll)n; i >= 1; i--) #define Loopdiag(i, j, h, w, sum) for(int i = ((sum) >= h ? h - 1 : (sum)), j = (sum) - i; i >= 0 && j < w; i--, j++) #define Loopdiagr(i, j, h, w, sum) for(int j = ((sum) >= w ? w - 1 : (sum)), i = (sum) - j; j >= 0 && i < h; j--, i++) #define Loopdiagsym(i, j, h, w, gap) for (int i = ((gap) >= 0 ? (gap) : 0), j = i - (gap); i < (h) && j < (w); i++, j++) #define Loopdiagsymr(i, j, h, w, gap) for (int i = ((gap) > (h) - (w) - 1 ? (h) - 1 : (w) - 1 + (gap)), j = i - (gap); i >= 0 && j >= 0; i--, j--) #define Loopitr(itr, container) for(auto itr = container.begin(); itr != container.end(); itr++) #define printv(vector) Loop(extra_i, vector.size()) { cout << vector[extra_i] << " "; } cout << endl; #define printmx(matrix) Loop(extra_i, matrix.size()) { Loop(extra_j, matrix[extra_i].size()) { cout << matrix[extra_i][extra_j] << " "; } cout << endl; } #define quickio() ios::sync_with_stdio(false); cin.tie(0); #define readfile(filename) ifstream in(filename); cin.rdbuf(in.rdbuf()); #define bitmanip(m,val) static_cast>(val) bool nearlyeq(double x, double y) { return abs(x - y) < 1e-9; } bool inrange(int x, int t) { return x >= 0 && x < t; } ll rndf(double x) { return (ll)(x + (x >= 0 ? 0.5 : -0.5)); } ll floorsqrt(double x) { ll m = (ll)sqrt(x); return m + (m * m <= (ll)(x) ? 0 : -1); } ll ceilsqrt(double x) { ll m = (ll)sqrt(x); return m + ((ll)x <= m * m ? 0 : 1); } ll rnddiv(ll a, ll b) { return (a / b + (a % b * 2 >= b ? 1 : 0)); } ll ceildiv(ll a, ll b) { return (a / b + (a % b == 0 ? 0 : 1)); } ll gcd(ll m, ll n) { if (n == 0) return m; else return gcd(n, m % n); } /*******************************************************/ // bitmask DP vi decode(int x) { vi ret; int p = 0; while (x > 0) { if (x & 1) ret.push_back(p); x >>= 1; p += 1; } return ret; } int encode(vi a) { int ret = 0; Loop(i, a.size()) { ret += (1 << a[i]); } return ret; } template class Partial_Combination { private: int n; vector> result; vvi combs; // iCj void core_func(const vector &a, int n, int r, int start) { if (r == 0) return; Loop(i, combs[n - 1][r - 1]) { result[start + i].push_back(a[Partial_Combination::n - n]); } if (n > 1) { core_func(a, n - 1, r - 1, start); core_func(a, n - 1, r, start + combs[n - 1][r - 1]); } } void make_combs(int n) { combs = vvi(n + 1, vi(n + 1)); Loop(i, n + 1) { combs[i][0] = 1; Loop1(j, i) { combs[i][j] = combs[i - 1][j - 1] + combs[i - 1][j]; } } } public: vector> get_partial_combination(const vector &a, int r) { n = int(a.size()); if (n < r) return {}; make_combs(n); result = vector>(combs[n][r]); core_func(a, n, r, 0); return result; } }; vvll dp; vvi table; Partial_Combination pc; ll solve(int xi, int xj) { if (dp[xi][xj] >= 0) return dp[xi][xj]; else { dp[xi][xj] = 0; int code = xi ^ (1 << xj); vi st = decode(code); vvi comb_list = pc.get_partial_combination(st, (st.size() + 1) / 2); Loop(i, comb_list.size()) { int b_side = encode(comb_list[i]); int a_side = xi - b_side; Loop(j, comb_list[i].size()) { if (table[xj][comb_list[i][j]] == 1) { dp[xi][xj] += solve(a_side, xj) * solve(b_side, comb_list[i][j]) * 2; } } } return dp[xi][xj]; } } int main() { int n = 16; table = vvi(n, vi(n)); Loop(i, n) { Loop(j, n) { cin >> table[i][j]; } } Loop(i, n) { Loop(j, i) { table[i][j] = -table[j][i]; } } int m = 1 << 16; dp = vvll(m, vll(n, -1)); Loop(i, n) { dp[encode({ i })][i] = 1; } vi a(n); Loop(i, n) a[i] = i; Loop(i, n) { cout << solve((1 << 16) - 1, i) << '\n'; } }