🦝 | CF1210F2
暴力是枚举每条边是否选,令
下面是一个我从别的地方抄来的爆标做法,复述一下()
上面差不多优化到极限了,换种思路。还可以用 Hall 定理或者流刻画完美匹配,显然这里前面合适一点。不同于对不满足定理的
令
(S,N(S)) ,(T,N(T)) 均为最优解,即v=|S|-|N(S)|=|T|-|N(T)| 且|S|=|T| 。放缩一下有
2v\le |S\cup T|-|N(S\cup T)|+|S\cap T|-|N(S\cap T)| ,其交集或并集必有更优选择。upd:注意这里取
\le 而不是= 的原因是|N(S)|+|N(T)|=|N(S)\cup N(T)|+|N(S)\cap N(T)| ,同时又|N(S)\cup N(T)|=|N(S\cup T)| ,但是|N(S)\cap N(T)|\ge |N(S\cap T)| 。
于是我们可以 dp 了。令
这里引入一个新状态
而且发现最后不用单独求答案了,
#define popc __builtin_popcount
#define subset(x, y) for (int y = (x - 1) & x; ~y; y = y ? ((y - 1) & x) : -1)
signed main() {
n = read();
for (int i = 0; i < n; i ++)
for (int j = 0; j < n; j ++)
a[i][j] = read() * qp(100, P - 2) % P,
b[i][j] = (P + 1 - a[i][j]) % P;
for (int s = 0; s < (1 << n); s ++)
for (int t = 0; t < (1 << n); t ++) {
yes[s][t] = no[s][t] = 1;
for (int j = 0; j < n; j ++) if (t >> j & 1) {
int res = 1;
for (int i = 0; i < n; i ++) if (s >> i & 1)
(no[s][t] *= b[i][j]) %= P, (res *= b[i][j]) %= P;
(yes[s][t] *= P + 1 - res) %= P;
}
if (!s) yes[s][t] = 1;
}
for (int s = 0; s < (1 << n); s ++)
for (int t = 0; t < (1 << n); t ++) {
bool flg = popc(s) <= popc(t);
int res = yes[s][t];
subset(s, s0) subset(t, t0)
if (popc(s0) - popc(t0) >= popc(s) - popc(t) || flg) {
int s1 = s ^ s0, t1 = t ^ t0;
(res += P - g[s0][t0] * f[s1][t1] % P * no[s0][t1] % P) %= P;
}
(flg ? f : g)[s][t] = res;
}
printf("%lld\n", f[(1 << n) - 1][(1 << n) - 1]);
return 0;
}