P3343 [ZJOI2015] 地震后的幻想乡 题解
:::::success[Hint 1] 考虑枚举边权之间的大小关系,然后得到一种暴力的做法。 ::::: :::::success[Hint 2] 我们考虑设出状压 DP 的状态,然后解决这个问题。 :::::
对应 Hint 1:
直接枚举每条边的具体大小是显然不现实的,我们考虑枚举边权之间的大小关系,然后我们考虑对其跑出最小生成树,然后我们求出最小生成树的最大边为第几小,显然若其为所有边第
对应 Hint 2:
对边状压仍然不理想,我们考虑对点状压,设
直接计算不好算,我们考虑正难则反这样我们每次钦定一个点
然后我们容易得到,答案就是:
这样我们就做完了这道题。
时间复杂度为
:::::success[code]
#include<bits/stdc++.h>
#define inl inline
#define int long long
#define lll __int128
#define fst ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define rep(i,x,y) for(int i=x;i<=(y);++i)
#define per(i,x,y) for(int i=x;i>=(y);--i)
#define rpr(i,x,y,z) for(int i=x;i<=(y);i+=z)
#define epe(i,x,y,z) for(int i=x;i>=(y);i-=z)
#define repe(i,x,y) for(i=x;i<=(y);++i)
#define endl '\n'
#define INF 1e18
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define lcm(x,y) x/__gcd(x,y)*y
#define ull unsigned long long
#define prr make_pair
#define pii pair<int,int>
#define gt(s) getline(cin,s)
#define at(x,y) for(const auto &x:y)
#define ff fflush(stdout)
#define mt(x,y) memset(x,y,sizeof(x))
#define idg isdigit
#define fp(s) string ssss=s;freopen((ssss+".in").c_str(),"r",stdin);freopen((ssss+\
".out").c_str(),"w",stdout);
#define sstr stringstream
#define all(x) x.begin(),x.end()
#define mcy(a,b) memcpy(a,b,sizeof(b))
#define ui unsigned
#define si signed
#define eb emplace_back
#define pff(x) ((x)*(x))
#define eush emplace
#define double long double
#define pdi pair<double,int>
#ifdef __unix__
#define gc getchar_unlocked
#else
#define gc _getchar_nolock
#endif
#ifdef __unix__
#define pc putchar_unlocked
#else
#define pc _putchar_nolock
#endif
using namespace std;
const int M=50,K=(1ll<<10)+5;
double binom[M][M],f[K][M];
int ind[K];
signed main(){
fst;
int n,m;
cin>>n>>m;
rep(i,0,m)
rep(j,0,i)
if(!j) binom[i][j]=1;
else binom[i][j]=binom[i-1][j-1]+binom[i-1][j];
rep(i,1,m){
int u,v;
cin>>u>>v;
++ind[1ll<<u-1|1ll<<v-1];
}
rep(i,1,n)
rep(j,0,(1ll<<n)-1)
if(j>>i-1&1) ind[j]+=ind[j^1ll<<i-1];
rep(i,1,(1ll<<n)-1)
rep(j,0,ind[i]){
f[i][j]=binom[ind[i]][j];
int p=i&i-1;
while(p){
if(p&(i&-i))
rep(k,0,ind[p]) f[i][j]-=f[p][k]*binom[ind[p^i]][j-k];
p=p-1&i;
}
}
double ans=1;
// rep(i,0,m) cout<<f[(1ll<<n)-1][i]<<' ';
// cout<<endl;
rep(i,0,m) ans-=f[(1ll<<n)-1][i]/binom[m][i]/(m+1);
cout<<fixed<<setprecision(6)<<ans<<endl;
return 'T'^'0'^'m'^'l'^'e';
}
:::::