【多校训练】hdu 5729 二分图
2017-06-19 11:51
246 查看
Rigid Frameworks
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 400 Accepted Submission(s): 325
Problem Description
Erik Demaine is a Professor in Computer Science at the Massachusetts Institute of Technology. Demaine's research interests range throughout algorithms, from data structures for improving web searches to the geometry of understanding how proteins fold to the
computational difficulty of playing games.
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?
Input
There are multiple test cases. For each test case, the first line contains two integer m and n (1≤m,n≤10) represented
the size of the grid graph.
Output
For each test case, output one integer number in a single line — the number of different rigid m × n grid graph with diagonal edges. The answer could be very large, output it modulo 1000000007(109+7).
Sample Input
1 2
3 2
7 9
10 10
Sample Output
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
[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 ,c ,d ; 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 [m]); }
相关文章推荐
- HDU多校联合训练 Problem1001 Abandoned country
- 【多校训练】hdu 6035 Colorful Tree 树状数组
- (2017多校训练第七场)HDU - 6127 Hard challenge 极角排序+尺取法
- HDU - 6143 Killer Names (多校训练,DP)
- hdu 4642 fliping game 多校联合训练第四场
- (2017多校训练第四场)HDU - 6069 Counting Divisors 区间筛
- 【多校训练】hdu 6077 Time To Get Up
- (2017多校训练第一场)HDU - 6034 Balala Power! 贪心
- 【多校训练】hdu 6181 Two Paths 次短路径 Dijkstra
- 2018HDU多校训练一 C -Triangle Partition
- 【多校训练】hdu 6178 Monkeys 贪心+dfs+读入挂模版
- 多校联合训练10&&HDU 5861 Road
- 【多校训练】hdu 6171 Admiral 双向bfs+hash
- hdu 4617 2013多校联合训练第二场weapon简单的计算几何
- 【多校训练】hdu 6045 Is Derek lying?
- HDU 6170 && 2017 多校训练:Two strings(DP)
- HDU 6178 && 2017 多校训练:Monkeys(DFS)
- 2017 多校训练第十场 HDU 6178 Monkeys 最小点覆盖+树形DP
- 【多校训练】hdu 6125 Free from square 状压dp+分组背包
- hdu 4970 Killing Monsters(数组的巧妙运用) 2014多校训练第9场