#include #include #include using namespace std; int main(){ int n; cin >> n; assert(1 <= n && n <= 18); int counton[n]; for(int i = 0; i < n; i++){ int tmp = 0; for(int j = 0; j < n; j++){ char c; cin >> c; assert(c == '0' || c == '1'); bool x = c == '1'; if(x) tmp += 1<> a[i], assert(0 <= a[i] && a[i] <= 100000); int ans = accumulate(a, a+n, 0); for(int i = 0; i < 1<>j)&1) score += a[j]; } // 枝刈り出来る(しなくてもよい) if(score >= ans) continue; int lie = i, confess = 0, k = -1; while(++k < n){ if((confess>>k)&1) continue; if((lie&counton[k]) == counton[k]){ confess |= 1<