热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

HDU5729RigidFrameworks(求二分图连通方案数)

RigidFrameworksTimeLimit:20001000MS(JavaOthers)MemoryLimit:6553665536K(JavaOthers)T

Rigid Frameworks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 281    Accepted Submission(s): 228

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.
Aflexible 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.
  Arigid 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 2016 Multi-University Training Contest 1 Recommend wange2014   |   We have carefully selected several similar problems for you:  5792 5790 5789 5788 5787 
题意:因为矩形是不稳定的,会变成平行四边形,就像这样 ,但是可以在矩形对角线加边,通过构成三角形使这个矩形稳定下来。给一n*m的矩形,可以在单位矩形里加两种对角线(从左上到右下,从左下到右上两种),或者不加对角线,或者两条。问使这个n*m的矩形稳定下来的方案数。
题解:原问题等价于求左边有n个点,右边有m个点的联通的二分图的数目 可以用类似连通图计数的方法dp得到,复杂度O(n^6)。 实际上是 projecteuler 434(点击打开链接).
那么如何计算一个二分图的连通方案数? 因为这由n*m个单位矩阵组成,每个单位矩阵可以加两种对角线(从左上到右下,从左下到右上两种),或者不加对角线,共3种选择,则一个n*m矩阵的总方案数是3^(n*m)。只要从所有方案中,除去不合法的方案数,就是合法的方案数。这么做的原因是因为不合法的方案数更容易求(只要二分图是不连通 的,这个方案就是不合法的)。
设dp[n][m]为使n*m矩阵固定下来的合法方案数。
从左边n个点中的点1固定,当连通块大小为i,j时,如何计算非法方案数,从 n-1个点中选出i-1个点(因为点1已经被固定了),从右边m个点中选出j个点,用这i,j个点组成连通块的数量就是,i+j大小的连通块有dp[i][j]个合法的存在方案,同时,下面的 n-i 个点和 m-j 个点有个组合方式。做法固定一个点,枚举这个点所处连通块的情况,只要这个连通块不包含二分图中所有的点,则当前的二分图一定是不连通的,一定是非法方案。
所以,转移方程为:
AC代码
#include
using namespace std;
const int MAXN=40;
const int mod=1e9+7;
long long fact[MAXN*MAXN],C[MAXN][MAXN],dp[MAXN][MAXN];

void init()
{
fact[0]=1;
for(int i=1;i<=110;++i) fact[i]=fact[i-1]*3%mod;
C[0][0]=1;
for(int i=1;i{
C[i][0]=C[i][i]=1;
for(int j=1;jC[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)
{
dp[i][j]=fact[i*j];
if(i==1&&j==0) dp[i][j]=1;
for(int n=1;n<=i;++n)
{
for(int m=0;m<=j;++m)
{
if(i==n&&j==m) continue;
dp[i][j]-=C[i-1][n-1]*C[j][m]%mod*dp[n][m]%mod*fact[(i-n)*(j-m)]%mod;
dp[i][j]=(dp[i][j]%mod+mod)%mod;
}
}
}
}

}
int main()
{
int m,n;
init();
while(~scanf("%d%d",&n,&m))
printf("%I64d\n",dp[n][m]);
return 0;
}




推荐阅读
  • CSS3选择器的使用方法详解,提高Web开发效率和精准度
    本文详细介绍了CSS3新增的选择器方法,包括属性选择器的使用。通过CSS3选择器,可以提高Web开发的效率和精准度,使得查找元素更加方便和快捷。同时,本文还对属性选择器的各种用法进行了详细解释,并给出了相应的代码示例。通过学习本文,读者可以更好地掌握CSS3选择器的使用方法,提升自己的Web开发能力。 ... [详细]
  • 本文介绍了九度OnlineJudge中的1002题目“Grading”的解决方法。该题目要求设计一个公平的评分过程,将每个考题分配给3个独立的专家,如果他们的评分不一致,则需要请一位裁判做出最终决定。文章详细描述了评分规则,并给出了解决该问题的程序。 ... [详细]
  • 本文讨论了使用差分约束系统求解House Man跳跃问题的思路与方法。给定一组不同高度,要求从最低点跳跃到最高点,每次跳跃的距离不超过D,并且不能改变给定的顺序。通过建立差分约束系统,将问题转化为图的建立和查询距离的问题。文章详细介绍了建立约束条件的方法,并使用SPFA算法判环并输出结果。同时还讨论了建边方向和跳跃顺序的关系。 ... [详细]
  • Python正则表达式学习记录及常用方法
    本文记录了学习Python正则表达式的过程,介绍了re模块的常用方法re.search,并解释了rawstring的作用。正则表达式是一种方便检查字符串匹配模式的工具,通过本文的学习可以掌握Python中使用正则表达式的基本方法。 ... [详细]
  • 本文介绍了一个在线急等问题解决方法,即如何统计数据库中某个字段下的所有数据,并将结果显示在文本框里。作者提到了自己是一个菜鸟,希望能够得到帮助。作者使用的是ACCESS数据库,并且给出了一个例子,希望得到的结果是560。作者还提到自己已经尝试了使用"select sum(字段2) from 表名"的语句,得到的结果是650,但不知道如何得到560。希望能够得到解决方案。 ... [详细]
  • 生成式对抗网络模型综述摘要生成式对抗网络模型(GAN)是基于深度学习的一种强大的生成模型,可以应用于计算机视觉、自然语言处理、半监督学习等重要领域。生成式对抗网络 ... [详细]
  • Iamtryingtomakeaclassthatwillreadatextfileofnamesintoanarray,thenreturnthatarra ... [详细]
  • IhaveconfiguredanactionforaremotenotificationwhenitarrivestomyiOsapp.Iwanttwodiff ... [详细]
  • Linux重启网络命令实例及关机和重启示例教程
    本文介绍了Linux系统中重启网络命令的实例,以及使用不同方式关机和重启系统的示例教程。包括使用图形界面和控制台访问系统的方法,以及使用shutdown命令进行系统关机和重启的句法和用法。 ... [详细]
  • 目录实现效果:实现环境实现方法一:基本思路主要代码JavaScript代码总结方法二主要代码总结方法三基本思路主要代码JavaScriptHTML总结实 ... [详细]
  • 本文讨论了在Windows 8上安装gvim中插件时出现的错误加载问题。作者将EasyMotion插件放在了正确的位置,但加载时却出现了错误。作者提供了下载链接和之前放置插件的位置,并列出了出现的错误信息。 ... [详细]
  • Android Studio Bumblebee | 2021.1.1(大黄蜂版本使用介绍)
    本文介绍了Android Studio Bumblebee | 2021.1.1(大黄蜂版本)的使用方法和相关知识,包括Gradle的介绍、设备管理器的配置、无线调试、新版本问题等内容。同时还提供了更新版本的下载地址和启动页面截图。 ... [详细]
  • 本文讨论了一个关于cuowu类的问题,作者在使用cuowu类时遇到了错误提示和使用AdjustmentListener的问题。文章提供了16个解决方案,并给出了两个可能导致错误的原因。 ... [详细]
  • ZSI.generate.Wsdl2PythonError: unsupported local simpleType restriction ... [详细]
  • 推荐系统遇上深度学习(十七)详解推荐系统中的常用评测指标
    原创:石晓文小小挖掘机2018-06-18笔者是一个痴迷于挖掘数据中的价值的学习人,希望在平日的工作学习中,挖掘数据的价值, ... [详细]
author-avatar
清宫佳伶330
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有