时间限制:10000ms
单点时限:1000ms
内存限制:256MB

描述

Given a directed graph containing n vertice (numbered from 1 to n) and m edges. Can you tell us how many different Hamiltonian Cycles are there in this graph?

A Hamiltonian Cycle is a cycle that starts from some vertex, visits each vertex (except for the start vertex) exactly once, and finally ends at the start vertex.

Two Hamiltonian Cycles C1, C2 are different if and only if there exists some vertex i that, the next vertex of vertex i in C1 is different from the next vertex of vertex i in C2.

输入

The first line contains two integers n and m. 2 <= n <= 12, 1 <= m <= 200.

Then follows m line. Each line contains two different integers a and b, indicating there is an directed edge from vertex a to vertex b.

输出

Output an integer in a single line -- the number of different Hamiltonian Cycles in this graph.

提示

额外的样例:

样例输入 样例输出
3 3
1 2               
2 1              
1 3
0

样例输入
4 7
1 2
2 3
3 4
4 1
1 3
4 2
2 1
样例输出
2

搜索大概也可以搞定。

  • 求哈密顿环的数目
  • 既然是环,且每个点都经过,我们假定一个起点,得到的结果是一样的,我的代码假定的是1为起点。
  • 这题有重边,但是必须两个点之间重边只看成一条边才能AC
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<cstring>
using namespace std;
int Mp[][];
int dp[<<][];//vis,now
int main()
{
int n,m,x,y,i,k,p,ans=;
scanf("%d%d",&n,&m);
for(i=;i<=m;i++){
scanf("%d%d",&x,&y);
Mp[x][y]=;
}
for(i=;i<=n;i++) dp[][]=;
for(i=;i<(<<n);i++)
{
for(k=;k<=n;k++)//now
{
if(!(i&(<<(k-)))) continue;
for(p=;p<=n;p++)//pre
{
if(!(i&(<<(p-)))||k==p) continue;
dp[i][k]=dp[i][k]+dp[i^(<<(k-))][p]*Mp[p][k];
}
}
}
for(i=;i<=n;i++) ans+=dp[(<<n)-][i]*Mp[i][];
printf("%d\n",ans);
return ;
}

最新文章

  1. Android ORM 框架之 greenDAO 使用心得
  2. 阿里云的9折推荐码 8DIER4
  3. ABAP 指針常用语法
  4. .net程序员转行做手游开发经历(二)
  5. EasyUI ComboGrid 分页
  6. SQL 代码创建表格以及CRUD
  7. oneThink 数据库连接失败,总提示密码不对的解决办法
  8. Redhat 显示系统版本号和内核版本号
  9. 【每日一摩斯】-【序列】-续-RAC and Sequences (853652.1)
  10. 用VS2010编写的C++程序,在其他电脑上无法运行,提示缺少mfc100.dll的解决办法
  11. 【HDOJ】3549 Flow Problem
  12. CentOS 7.2下安装Mono 5.0
  13. 白话skynet第二篇:skynet的通信调试pack和sprotol
  14. lua 的 break
  15. 转:嵌入式: jffs2,yaffs2,logfs,ubifs文件系统性能分析
  16. lsyncd —— 多机器实时同步文件神器
  17. 【Common】NO.81.Note.1.Common.1.002-【文章摘要】
  18. ABBYY FineReader Pro for Mac有哪些特性(下)
  19. MFC从资源加载文本
  20. 收集的一些python基础教学博客

热门文章

  1. 大觅网01Day
  2. 分布式锁用Redis还是ZooKeeper?(转载)
  3. 使用choco 在windows 环境安装kubectl 并配置
  4. leveldb Arena源码分析
  5. supervisor管理superset
  6. Windows文件共享配置与遇到的问题
  7. spring依赖注入三种方式
  8. # 数字签名&amp;数字证书
  9. java基础: synchronized与Lock的区别
  10. Scala学习二——控制结构和函数