B - Bipartite Bicolored Graphs
qqqaaazzz_qwq · · 个人记录
https://codeforces.com/gym/100524 Bipartite Bicolored Graphs
定义一张二分图的价值是
求所有
Solution
令
你需要敏锐的察觉到,
时间复杂度 那么
#include <bits/stdc++.h>
#define FAST ios::sync_with_stdio(false);cin.tie(0)
#define int long long
using namespace std;
/*
by qqqaaazzz
f[i] 表示大小为 i 的联通二分图个数
g[i] 表示分成 C 个二分图的方案数,系数乘 2^C
h[i] 表示答案
*/
const int N = 4e6;
int fac[N+10];
int mny[N+10];
const int p = 175781251;
int fpm(int a,int b){
int c = a, ans = 1;
while(b){
if((b&1)==1) ans = (ans*c)%p;
c = (c*c)%p;
b >>= 1;
}
return ans;
}
void init()
{
fac[0]=1;
mny[0]=1;
for (int i=1;i<=N;i++){
fac[i]=(fac[i-1]*i)%p;
}
mny[N]=fpm(fac[N],p-2);
for (int i=N-1;i>=0;i--){
mny[i]=(mny[i+1]*(i+1))%p;
}
return;
}
int C(int n,int m){
if(n<m) return 0;
int ans = fac[n];
ans = (ans*mny[m])%p;
ans = (ans*mny[n-m])%p;
return ans;
}
int f[100010],g[100010],h[100010];
signed main()
{
freopen("bipartite.in","r",stdin);
freopen("bipartite.out","w",stdout);
init();
h[0] = 1;
for (int i=1;i<=100;i++){
//算 g[i]
for (int j=0;j<=i;j++){
g[i] = (g[i]+C(i,j)*fpm(3,j*(i-j))%p)%p;
}
//算 f[i]
f[i] = g[i];
for (int j=1;j<=i-1;j++){
f[i] = (f[i]-2*f[j]*g[i-j]%p*C(i-1,j-1)%p+p)%p;
}
f[i] = (f[i]*87890626)%p;
//算 h[i]
for (int j=1;j<=i;j++){
h[i] = (h[i]+f[j]*h[i-j]%p*C(i-1,j-1))%p;
}
}
while(1){
int n;
cin >> n;
if(!n) return 0;
cout << h[n] << "\n";
}
return 0;
}
后话:你惊讶的发现,把第一个循环里面的