博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CodeForces 11D A Simple Task (DP解哈密顿路径数目)
阅读量:2233 次
发布时间:2019-05-09

本文共 1565 字,大约阅读时间需要 5 分钟。

D. A Simple Task
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Given a simple graph, output the number of simple cycles in it. A simple cycle is a cycle with no repeated vertices or edges.

Input

The first line of input contains two integers n and m (1 ≤ n ≤ 190 ≤ m) – respectively the number of vertices and edges of the graph. Each of the subsequent m lines contains two integers a and b, (1 ≤ a, b ≤ na ≠ b) indicating that vertices a and b are connected by an undirected edge. There is no more than one edge connecting any pair of vertices.

Output

Output the number of cycles in the given graph.

Sample test(s)
input
4 61 21 31 42 32 43 4
output
7
Note

The example graph is a clique and contains four cycles of length 3 and three cycles of length 4.

题意:

求一个图中(节点个数小于20)长度大于等于三的哈密顿路径数目。

思路:

点数不多,类似TSP,用状压dp解决。

dp[i][j]表示状态为i时。以j结尾的路径条数。

假设下一个点能回到已经走过的一个点中,那么就是一个回路了。

为了避免反复计算,回到的点为走过的最小的点。(这是一个优化,少了枚举最小点这个循环)

长度为2的哈密顿路径会计算到,能够不做处理,最后减去边的条数就可以,每一个环会算两遍,最后要除以2.

代码:

#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define maxn 205#define MAXN 100005#define mod 1000000009#define INF 0x3f3f3f3f#define pi acos(-1.0)#define eps 1e-6typedef long long ll;using namespace std;ll n,m,ans,flag,cnt,tot;ll mp[20][20],dp[1<<19][19];int first(int s){ for(int i=0;i

转载于:https://www.cnblogs.com/ljbguanli/p/6900053.html

你可能感兴趣的文章
Oracle知识点连载(二)
查看>>
Oracle知识点连载(三)
查看>>
Oracle知识点连载(五)
查看>>
关于三元运算符的类型转换问题
查看>>
笔记本怎么设置WIfi热点
查看>>
如何实现字符串的反转及替换?
查看>>
Java面试题全集(上)
查看>>
Java面试题全集(中)
查看>>
值传递和引用传递
查看>>
什么情况下用+运算符进行字符串连接比调用StringBuilder对象的append方法连接字符串性能更好?
查看>>
怎么根据Comparable方法中的compareTo方法的返回值的正负 判断升序 还是 降序?
查看>>
理解事务的4种隔离级别
查看>>
常用正则匹配符号
查看>>
建议42: 让工具类不可实例化
查看>>
Java 异步机制与同步机制的区别
查看>>
hibernate的对象三种状态说明
查看>>
什么是N+1查询?
查看>>
Spring 接管 Hibernate 配置 延迟加载
查看>>
找出不在预定数组中的自然数
查看>>
String常见面试题
查看>>