您的位置:首页 > 大数据 > 人工智能

2016 Multi-University Training Contest 1 G. Rigid Frameworks

2016-08-31 18:55 344 查看

Rigid Frameworks

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


[align=left]Problem Description[/align]
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.

const int N = 15, MOD = 1e9 + 7;
int n, m, f

, all[N * N], C

;

inline int add(int x, int y) {
return (((x + y) % MOD) + MOD) % MOD;
}

inline int mul(int x, int y) {
return (((x * 1ll * y) % MOD) + MOD) % MOD;
}

inline void init() {
all[0] = 1;
for(int i = 1; i < 15 * 15; ++i) all[i] = mul(all[i - 1], 3);

for(int i = 0; i < N; ++i) C[i][0] = 1;
for(int i = 1; i < N; ++i)
for(int j = 1; j < N; ++j)
C[i][j] = add(C[i - 1][j - 1], C[i - 1][j]);

for(int n = 1; n <= 10; ++n)
for(int m = 0; m <= 10; ++m) {
f
[m] = all[n * m];
for(int lef = 0; lef < n; ++lef)
for(int rig = 0; rig <= m; ++rig) {
if(lef == n - 1 && rig == m) continue;
f
[m] = add(f
[m],
-mul(mul(mul(C[n - 1][lef], C[m][rig]),
f[lef + 1][rig]),
all[(n - lef - 1) * (m - rig)]));
}
}
}

int main() {
init();
while(scanf("%d%d", &n, &m) == 2) printf("%d\n", f
[m]);
return 0;
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: