您的位置:首页 > 其它

PE 434 Rigid graphs && HDU 5729 Rigid Frameworks

2016-07-21 11:03 218 查看
给定n*m的方格,每个方格只能在其中一条对角线上加边,求使所有的方格稳固的加边方案数。

n,m≤10

具体:https://projecteuler.net/problem=434

转化:求左边有n个点,右边有m个点的联通二分图的数目。

PS:2016多校#1的题。虽说有原题,但对有人刷PE这事还是蛮钦佩的。

连通图计数

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cassert>
#include<ctime>
#include<bitset>
#include<queue>
#include<set>
#define inf (1<<30)
#define INF (1ll<<62)
#define prt(x) cout<<#x<<":"<<x<<" "
#define prtn(x) cout<<#x<<":"<<x<<endl
using namespace std;
typedef long long ll;
template<class T>void sc(T &x){
x=0;char c;int f=1;
while(c=getchar(),c<48)if(c=='-')f=-1;
do x=x*10+(c^48);
while(c=getchar(),c>47);
x*=f;
}
template<class T>void nt(T x){
if(!x)return;
nt(x/10);
putchar('0'+x%10);
}
template<class T>void pt(T x){
if(x<0)putchar('-'),x=-x;
if(!x)putchar('0');
else nt(x);
putchar('\n');
}
const int mod=1000000007;
const int maxn=10;
ll dp[16][16],f[16][16];
ll C[16][16];
ll pow3[104];
ll qpow(ll a,ll b){
ll c=1;
for(;b;b>>=1,a=(a*a)%mod)
if(b&1)c=(c*a)%mod;
return c;
}
ll fac[16];
int main(){
//  freopen("pro.in","r",stdin);
//  freopen("chk.out","w",stdout);
pow3[0]=1;
for(int i=1;i<=100;i++)pow3[i]=pow3[i-1]*3%mod;

fac[0]=1;
for(int i=1;i<=maxn;i++)fac[i]=fac[i-1]*i%mod;

for(int i=1;i<=maxn;i++){
for(int j=1;j<i;j++)
C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
C[i][0]=C[i][i]=1;
}
for(int i=0;i<=maxn;i++)
for(int j=0;j<=maxn;j++)
f[i][j]=1;//

for(int i=1;i<=maxn;i++){
for(int j=1;j<=maxn;j++){
dp[i][j]=pow3[i*j]-f[i][j];
if(dp[i][j]<0)dp[i][j]+=mod;

for(int k=maxn;k>=i;k--){
for(int l=maxn;l>=j;l--){
for(int t=min(k/i,l/j);t>=1;t--){
ll res=f[k-i*t][l-j*t];
for(int a=k-i*t,b=l-j*t;a<k&&b<l;a+=i,b+=j)
res=dp[i][j]*C[a+i][i]%mod*C[b+j][j]%mod*res%mod;
res=res*qpow(fac[t],mod-2)%mod;
f[k][l]=(f[k][l]+res)%mod;
}
}
}
}
}
int n,m;
while(~scanf("%d%d",&n,&m))
pt(dp
[m]);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: