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这事还是蛮钦佩的。
连通图计数
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; }
相关文章推荐
- Windows与USB的通信
- android studio编写运行java main的三种方法(亲测)
- android 如何编译release版本的应用
- 走遍中国 —— 东三省
- node.js把jade改为html的方法
- JavaScript调用安卓函数
- Symbols in Interllij IDEA
- 关于前端安全性
- 多图点击放大并左右滑动
- POJ 1064 青蛙的约会(拓展欧几里德算法)
- [LeetCode] 43. Multiply Strings
- VOS 系统报错,系统挂断 VOS不通,各种vos疑难杂病都在这里
- 视频背景抠图(opencv)
- 投票操作管理系统
- [编程题]最大子方阵
- WIN10 显示右下角应用图标
- Java 集合:Collection,List,ArrayList,Vector,LinkedList(实现方式,对比)
- dialog窗口打开新页面
- 网页设计中常用的Web安全字体
- Spring学习笔记3——消息队列(rabbitmq), 发送邮件