CF11D:A Simple Task(状压dp & 图)
来源:互联网 发布:如何编译linux源码 编辑:程序博客网 时间:2024/05/21 11:24
D. A Simple Task
time limit per test
2 secondsmemory limit per test
256 megabytesinput
standard inputoutput
standard outputGiven 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 ≤ 19, 0 ≤ 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 ≤ n, a ≠ 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.
Examples
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.
思路:转成计算有几条链能成环,限定链上最小的数字为起点,dp[i][j]为i状态下,以j为终点的链有几条,最后答案除二即可。
# include <bits/stdc++.h>using namespace std;int v[20][20]={0};long long dp[1<<20][20]={0};int main(){ int n, m, st=0; long long ans=0; scanf("%d%d",&n,&m); while(m--) { int a, b; scanf("%d%d",&a,&b); --a;--b; v[a][b] = v[b][a] = 1; } for(int i=0; i<n; ++i) dp[1<<i][i] = 1; for(int i=1; i<1<<n; ++i) { for(int j=0; j<n; ++j) { if(dp[i][j] == 0) continue; for(int k=0; k<n; ++k) { if(i&(1<<k)) { st = k; break; } } if(v[j][st] && __builtin_popcount(i)>2) ans += dp[i][j]; for(int k=st+1; k<n; ++k) if(!(i&(1<<k)) && v[j][k]) dp[i|(1<<k)][k] += dp[i][j]; } } printf("%lld\n",ans/2); return 0;}
阅读全文
0 0
- CF11D:A Simple Task(状压dp & 图)
- CF11D A Simple Task
- Codeforces 11D - A Simple Task (状压DP)
- Codeforces Beta Round #11 D. A Simple Task(状压DP)
- [无向图简单环计数 状压DP] Codeforces 11D Beta Round #11 D. A Simple Task
- CodeForces 11D A Simple Task (DP解哈密顿路径数目)
- Codeforces 11D A Simple Task (状态压缩DP)
- CodeForces 11D - A Simple Task 状态压缩DP
- HDU1339:A Simple Task
- hdu1339-A Simple Task
- A Simple Task
- HDU A Simple Task
- A Simple Task
- A Simple Task
- 1339.A Simple Task
- WOJ1154-A Simple Task
- HDOJ1339 A Simple Task
- Codeforces Beta Round #11, problem: (D) A Simple Task 状态压缩DP+记忆化搜素DP
- (原) 环信3.0 web实时视频通话 版本1.4.8
- C++中整型类型转换成字符串类型
- 两个栈实现一个队列,两个队列实现一个栈
- 设备驱动及Linux设备号
- xpath中如何使用变量
- CF11D:A Simple Task(状压dp & 图)
- 集合框架——TreeMap练习(字母出现的次数)
- 生成对抗网络GAN损失函数Loss的计算
- YUV格式
- 使用TP3.2框架时遇到Call to a member function assign() on a non-object
- angularjs中日期的回显
- CCF 201609-1最大波动java
- 【数据库基础】用SQL语言关键字表示关系代数的交 并 差 内连接 外连接操作
- 微信小程序-问题:未找到入口 app.json 文件