Rigid Frameworks
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 400 Accepted Submission(s): 325
Maid xiaodao is learning theoretical computer science in her spare time, and recently she was fascinated by Professor Erik Demaine's Geometric Folding Algorithms - Linkages, Origami, Polyhedra. The following problem was inspired by this book.
Recall that a graph is a collection of vertices and edges connecting the vertices, and that two vertices connected by an edge are called adjacent. Graphs can be embedded in Euclidean space by associating each vertex with a point in the Euclidean space.
⋅ A flexible graph is an embedding of a graph where it is possible to move one or more vertices continuously so that the distance between at least two nonadjacent vertices is altered while the distances between each pair of adjacent vertices is kept constant.
⋅ A rigid graph is an embedding of a graph which is not flexible. Informally, a graph is rigid if by replacing the vertices with fully rotating hinges and the edges with rods that are unbending and inelastic, no parts of the graph can be moved independently from the rest of the graph.
Sit down and relax, to simplify the problem, let's only consider the planar graphs as grids. The grid graphs embedded in the Euclidean plane are not rigid, as the following animation demonstrates:
However, one can make them rigid by adding diagonal edges to the cells. For example, the following picture shows a 2 × 3 grid graph.
Note that you can add at most one orientation of a diagonal edge in one single cell. In fact, there are 448 ways to make a 2 × 3 grid graph rigid. And now we want to know, how many different rigid m × n grid graph with diagonal edges in total? Dear contestant, could you please find it out?
1 2 3 2 7 9 10 10
4 448 357533852 935300639
这题确实比较难,参考了博客:http://blog.csdn.net/dpppbr/article/details/51972196 对我帮助很大
有几个难点:
1. 将问题转换成连通二分图计数问题
固定一个正方形可以使它的横边和竖边垂直。而对于同一行的正方形,他们的竖边是平行的。对于同一列的正方形,他们的横边也是平行的。 因此,固定一个正方形,就能是 当前行的竖边 和 当前列的横边 垂直。
现在可以转化成二分图,横边和竖边分别为两个部分。如果固定一个正方形,就将相应的点连边。
我们的目标是将所有的横边和所有的竖边都垂直。也就是左边任意的一个点要能到达右边任意一个点,也就是二分图连通。统计方案数也就是统计二分图连通的数量。
ps:左2垂直右1,左1垂直右1,左1垂直右2-> 左2平行左1,左1垂直右2 -> 左2垂直右2
2. 求解连通二分图计数问题
因为一个正方形可以连两种边或者不连边,3种。对应的二分图两点之间也有3种。所以左n个点,右m个点的任意二分图就有3^(n+m)种。 然后我们除去不连通的情况,就能得到连通的情况。
设dp[n][m]为左边n个点,右边m个点的连通二分图数。可递归求出:
其中是从取出左i个点,右j个点的连通子图的取法, (需要固定一个点,所以左边从n-1个点钟取出i-1个点)①。
为剩余的点随意取。
最后设置临界值dp[1][0]=1,代表只有一个点的情况即可。
①有可能有k个大小为(i,j)连通子图,而我们的方法是取一个连通子图,然后剩余的随意取。
这样可能出现重复统计的情况。所以这里的技巧是固定一个点。
PS:感谢q神和吉利爷的解答
#include <iostream>
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll MOD=1000000007;
const int N=120;
ll fac[N],c[N][N],d[N][N];
int main()
{
fac[0]=1;
for(int i=1;i<=110;i++) fac[i]=fac[i-1]*3%MOD;
for(int i=0;i<=10;i++)
{
c[i][0]=c[i][i]=1;
for(int j=1;j<i;j++)
c[i][j]=(c[i-1][j]+c[i-1][j-1])%MOD;
}
for(int i=1;i<=10;i++)
for(int j=0;j<=10;j++)
{
d[i][j]=fac[i*j];
for(int x=1;x<=i;x++)
for(int y=0;y<=j;y++)
{
if(x==i&&y==j) continue;
d[i][j]-=(((c[i-1][x-1]*c[j][y]%MOD)*d[x][y]%MOD)*fac[(i-x)*(j-y)])%MOD;
d[i][j]=(d[i][j]+MOD)%MOD;
}
}
int n,m;
while(~scanf("%d%d",&n,&m)) printf("%lld\n",d[n][m]);
}