查看代码
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 20;
const int mod = 1e9+7;
ll qpow(ll a,ll b){ll res=1;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll a[maxn][maxn];
ll g[1<<17],f[1<<17];
int main()
{
#ifndef ONLINE_JUDGE
freopen("simple.in", "r", stdin);
freopen("simple.out", "w", stdout);
#endif
int n;
scanf("%d",&n);
int mx = 1<<n;
for(int i = 0;i < n;++i){
for(int j = 0;j < n;++j)scanf("%lld",&a[i][j]);
}
for(int i = 1;i < mx;++i){
g[i]=1;
for(int j = 0;j < n;++j){
for(int k = 0;k < j;++k){
if(((i>>j)&1)&&((i>>k)&1)){
g[i]=g[i]*(a[j][k]+1)%mod;
}
}
}
ll tmp = 0;
for(int j = i&(i-1);j;j = i&(j-1)){
if(j&(i&-i))
tmp=(f[j]*g[i^j]+tmp)%mod;
}
f[i]=(g[i]-tmp+mod)%mod;
}
cout<<f[mx-1]<<endl;
return 0;
}