2016 Multi-University Training Contest 1 G. Rigid Frameworks

Rigid Frameworks

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 337    Accepted Submission(s): 273


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.

 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.

 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 (1m,n10) 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
 

 

Author
HIT
 

 

Source

 

题意:
    一个n*m的网格,如题目中图片所示。
    所有的点都是交接点,所有的直线都是不可拉伸的铁棍。
    这样这个网格是可以活动的。
    现在可以在某些网格中在对角线上添加不可拉伸的铁棍。
    同一个网格只能添加一次。
    这样添加完后,若网格个不可活动,则为稳定。

    问,使网格稳定的添边方式有多少种?
题解:
    首先,要知道:
    1、每一列水平的直线之间是平行的,每一行竖直的直线之间也是平行的。
    2、题目要求的稳定,就是要求横着的直线和竖着的直线都垂直。
    这里的直线是那一条条小线段,下文中的小直线、直线都是一个意思。

    如果我在第(i,j)个格子添加了斜线,
    那么第i行的小直线和第j列小直线就必然垂直了。
    


    所以如果我把这n个行作为左边的点,m个列作为右边的点。
    添加对角线使它们垂直就相当于在对应点对之间连一条边。
    注意这种垂直关系是可以传递的。

    所以问题转换成了,是一个左边n个点,右边m个点的二分图,
    有多少种方式连边使它们连通。
    其中每个点对的连边方式有两种(主对角线、副对角线)


    

    那么这个方式怎么统计?
    若是随意连边,总方案数为3^(n*m)种。
    因为n*m对边可以连,也可以不连,连有两种,不连一种。

    考虑二分图不连通的方案数:
        那么至少左边1号点所在的连通快不会包含所有点。

        所以只需要枚举1号点所在的连通快大小,
        计算出当1号点所在连通块大小为所枚举的时候的方案数就可以了。
        枚举时可以枚举1号点所在连通块左边有i个点,右边有j个点。
        那么连边方案数就为f[i][j],恰好是个子问题。

所以若令f[n][m]为左边n个点,右边m个点的二分图的连通方案数。
f[n][m] = 3^(n*m) - 
            sigma(0<=i<n, sigma(0<=j<=m,    
                f[i + 1][j] * C(n - 1, i) * C(m, j) * 3^(  (n-1-i)*(m-j)  )      
            ))        

  

 

 1 const int N = 15, MOD = 1e9 + 7;
 2 int n, m, f[N][N], all[N * N], C[N][N];
 3 
 4 inline int add(int x, int y) {
 5     return (((x + y) % MOD) + MOD) % MOD;
 6 }
 7 
 8 inline int mul(int x, int y) {
 9     return (((x * 1ll * y) % MOD) + MOD) % MOD;
10 }
11 
12 inline void init() {
13     all[0] = 1;
14     for(int i = 1; i < 15 * 15; ++i) all[i] = mul(all[i - 1], 3);
15 
16     for(int i = 0; i < N; ++i) C[i][0] = 1;
17     for(int i = 1; i < N; ++i)
18         for(int j = 1; j < N; ++j)
19             C[i][j] = add(C[i - 1][j - 1], C[i - 1][j]);
20 
21     for(int n = 1; n <= 10; ++n)
22         for(int m = 0; m <= 10; ++m) {
23             f[n][m] = all[n * m];
24             for(int lef = 0; lef < n; ++lef)
25                 for(int rig = 0; rig <= m; ++rig) {
26                     if(lef == n - 1 && rig == m) continue;
27                     f[n][m] = add(f[n][m], 
28                             -mul(mul(mul(C[n - 1][lef], C[m][rig]), 
29                                 f[lef + 1][rig]), 
30                                 all[(n - lef - 1) * (m - rig)]));
31                 }
32         }
33 }
34 
35 int main() {
36     init();
37     while(scanf("%d%d", &n, &m) == 2) printf("%d\n", f[n][m]);
38     return 0;
39 }
View Code

 

posted @ 2016-08-31 18:55  yanzx6  阅读(280)  评论(0编辑  收藏  举报