[ABC213G] Connectivity 2 题解
[ABC213G] Connectivity 2 Solution
更好的阅读体验戳此进入
题面
给定
Solution
对于 FZT(子集计数)的更具体说明可以参考 FZT - 子集计数学习笔记。
考虑 FZT,显然令
令
不难想到,若
考虑如何转移
可以尝试理解一下这个转移,我们要保证
然后发现,这个东西是假的。不难想到,假设我们考虑一个将
于是转移优化为:
然后因为我们要保证
同时不难对于初始值,存在
然后考虑答案,不难想到,对于点
然后这个求解的复杂度为
最终复杂度为
Tips:对于枚举子集的过程应该不用多说,令 for(int S = Smx; S; S = (S - 1) & Smx)
,具体证明这里不再赘述,可以网上直接搜一下。
Tips:然后关于前面说的枚举子集和子集的子集的复杂度,这个东西用组合数写一下不难证明,总之枚举
Code
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define PI M_PI
#define E M_E
#define npt nullptr
#define SON i->to
#define OPNEW void* operator new(size_t)
#define ROPNEW(arr) void* Edge::operator new(size_t){static Edge* P = arr; return P++;}
using namespace std;
mt19937 rnd(random_device{}());
int rndd(int l, int r){return rnd() % (r - l + 1) + l;}
bool rnddd(int x){return rndd(1, 100) <= x;}
typedef unsigned int uint;
typedef unsigned long long unll;
typedef long long ll;
typedef long double ld;
#define MOD (ll)(998244353ll)
#define MAX_STATUS (150000)
#define EXIST(x) (S & (1 << ((x) - 1)))
template < typename T = int >
inline T read(void);
int N, M;
struct Edge{
Edge* nxt;
int to;
OPNEW;
}ed[2100];
ROPNEW(ed);
Edge* head[20];
ll F[MAX_STATUS], G[MAX_STATUS];
ll pow2[500];
ll ans[20];
int main(){
pow2[0] = 1;
for(int i = 1; i <= 300; ++i)pow2[i] = pow2[i - 1] * 2 % MOD;
N = read(), M = read();
const int Smx = (1 << N) - 1;
for(int i = 1; i <= M; ++i){
int s = read(), t = read();
head[s] = new Edge{head[s], t};
}F[0] = G[0] = 1;
for(int S = Smx; S; S = (S - 1) & Smx){
int cnt(0);
for(int p = 1; p <= N; ++p)
if(EXIST(p))
for(auto i = head[p]; i; i = i->nxt)
if(EXIST(SON))++cnt;
G[S] = pow2[cnt];
}
for(int S = 1; S <= Smx; ++S){
for(int T = (S - 1) & S; T; T = (T - 1) & S)
if(T & 1)
(F[S] += F[T] * G[S ^ T] % MOD) %= MOD;
F[S] = (G[S] - F[S] + MOD) % MOD;
}
for(int i = 2; i <= N; ++i)
for(int S = Smx; S; S = (S - 1) & Smx)
if(EXIST(i) && EXIST(1))(ans[i] += F[S] * G[S ^ Smx] % MOD) %= MOD;
for(int i = 2; i <= N; ++i)printf("%lld\n", ans[i]);
// for(int S = Smx; S; S = (S - 1) & Smx)
// cout << "G[" << bitset < 6 >(S) << "] = " << G[S] << ", F = " << F[S] << endl;
fprintf(stderr, "Time: %.6lf\n", (double)clock() / CLOCKS_PER_SEC);
return 0;
}
template < typename T >
inline T read(void){
T ret(0);
int flag(1);
char c = getchar();
while(c != '-' && !isdigit(c))c = getchar();
if(c == '-')flag = -1, c = getchar();
while(isdigit(c)){
ret *= 10;
ret += int(c - '0');
c = getchar();
}
ret *= flag;
return ret;
}
UPD
update-2022_12_05 初稿
本文作者:tsawke
本文链接:https://www.cnblogs.com/tsawke/p/17032748.html
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步