CF1210F2
吐槽:NOIP模拟赛出了此题的加强版,其数据范围是 ,过于变态。
对于二分图完美(完备)匹配,套路地考虑Hall定理,令 ,则存在完美匹配等价于 。使得所有的 都满足这个条件太难计数了,容斥一下,对存在 满足 的图计数,考虑对每个这样的形式钦定 最大的集合中 最小的作为代表元,可以证明,每个不合法的图其代表元都是唯一的,那么考虑对代表元容斥。
令 表示考虑左部点集合为 ,,其不存在完美匹配且 是代表元的方案数, 表示这个导出子图的匹配方案数,即 的方案数。那么考虑容斥掉代表元不是 ,而是 的子集 ,其需要满足 ,如图:
首先 之间的方案数是 ,并且要强制钦定 ,因此 之间不能有边,用 表示这个方案数。对于 之间的连边,我们发现其一定要形成完美匹配,否则可以并上其中的某个不合法点集,这样 就变大了,不应在此处计数,因此我们还需要记 表示 之前有完美匹配的方案数,于是不难得到转移:
我们还需要求出 ,可以枚举子集 表示其作为不合法位置且其作为代表元,即使用 进行容斥:
最终答案就是 。时间复杂度可以分 计算量分别看,是 。
代码
#include <bits/stdc++.h>
#define popc(x) __builtin_popcount(x)
using namespace std;
typedef long long ll;
const int mod=1e9+7;
inline int Mod(int x) { return x<0 ? x+mod : (x>=mod ? x-mod : x); }
inline void adm(int &x,int y) { x=Mod(x+y); }
inline void dec(int &x,int y) { x=Mod(x-y); }
inline void pro(int &x,int y) { x=(ll)x*y%mod; }
inline int qmi(ll a,int b)
{
ll res=1;
for (;b;b>>=1,a=a*a%mod) if (b&1) res=res*a%mod;
return res;
}
const int N=9;
int n;
int p[N][N];
int G[1<<N][1<<N],no[1<<N][1<<N];
int g[1<<N][1<<N],f[1<<N][1<<N];
int main()
{
freopen("magician.in","r",stdin);
freopen("magician.out","w",stdout);
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cin >> n;
int inv=qmi(100,mod-2);
for (int i=0;i<n;i++)
{
for (int j=0;j<n;j++)
{
cin >> p[i][j];
pro(p[i][j],inv);
}
}
for (int S=0;S<(1<<n);S++)
{
for (int T=0;T<(1<<n);T++)
{
G[S][T]=1;
for (int y=0;y<n;y++)
{
if (!(T>>y&1)) continue; int pr=1;
for (int x=0;x<n;x++) if (S>>x&1) pro(pr,Mod(1-p[x][y]));
pro(G[S][T],Mod(1-pr));
}
no[S][T]=1;
for (int x=0;x<n;x++) if (S>>x&1) for (int y=0;y<n;y++) if (T>>y&1) pro(no[S][T],Mod(1-p[x][y]));
}
}
for (int S=0;S<(1<<n);S++)
{
for (int T=0;T<(1<<n);T++)
{
if (popc(S)<=popc(T))
{
f[S][T]=G[S][T];
for (int s=S;;s=(s-1)&S)
{
for (int t=T;;t=(t-1)&T)
{
if (s || t)
if (g[s][t] && no[s][T^t] && f[S^s][T^t])
dec(f[S][T],(ll)g[s][t]*no[s][T^t]%mod*f[S^s][T^t]%mod);
if (!t) break;
}
if (!s) break;
}
}
else
{
g[S][T]=G[S][T];
for (int s=S;;s=(s-1)&S)
{
for (int t=T;;t=(t-1)&T)
{
if (s!=S || t!=T)
if (popc(s)-popc(t)>=popc(S)-popc(T))
if (g[s][t] && no[s][T^t] && f[S^s][T^t])
dec(g[S][T],(ll)g[s][t]*no[s][T^t]%mod*f[S^s][T^t]%mod);
if (!t) break;
}
if (!s) break;
}
}
}
}
cout << f[(1<<n)-1][(1<<n)-1] << "\n";
return 0;
}