正题

题目链接:https://www.luogu.com.cn/problem/CF11D


题目大意

给出\(n\)个点\(m\)条边的一张简单无向图,求它的简单环的个数。

\(1\leq n\leq 19\)


解题思路

首先算重的问题很麻烦但也是解决这题的关键。

因为防止算重那么我们就只考虑在每个环编号最小的节点统计一次。

枚举一个起点,然后后面就只走编号大于其的节点用状压计算方案数即可。

时间复杂度\(O(2^nn^2)\)


code

#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const ll N=19;
ll n,m,f[N][1<<N],ans;
bool a[N][N];
signed main()
{
scanf("%lld%lld",&n,&m);
for(ll i=1,x,y;i<=m;i++){
scanf("%lld%lld",&x,&y);x--;y--;
a[x][y]=a[y][x]=1;
}
ll MS=(1<<n),pre=0;
for(ll p=0;p<n;p++){
pre|=(1<<p);
for(ll s=0;s<MS;s++){
if(s&pre)continue;
for(ll i=0;i<n;i++)f[i][s]=0;
}
f[p][0]=1;
for(ll s=0;s<MS;s++){
if(s&pre)continue;
for(ll i=p;i<n;i++){
if(!f[i][s])continue;
for(ll j=p+1;j<n;j++){
if((s>>j)&1)continue;
if(a[i][j])f[j][s|(1<<j)]+=f[i][s];
}
if(a[i][p]&&s!=(s&-s))
ans+=f[i][s];
}
}
}
printf("%lld\n",ans/2);
return 0;
}

CF11D-A Simple Task【状压dp】的更多相关文章

  1. CF11D A Simple Task 状压DP

    传送门 \(N \leq 19\)-- 不难想到一个状压:设\(f_{i,j,k}\)表示开头为\(i\).结尾为\(j\).经过的点数二进制下为\(k\)的简单路总数,贡献答案就看\(i,j\)之间 ...

  2. CF11D A Simple Task(状压DP)

    \(solution:\) 思路大家应该都懂: 状压DP:\(f[i][j]\),其中 \(i\) 这一维是需要状压的,用来记录19个节点每一个是否已经走过(走过为 \(1\) ,没走为 \(0\) ...

  3. FZU - 2218 Simple String Problem(状压dp)

    Simple String Problem Recently, you have found your interest in string theory. Here is an interestin ...

  4. FZU - 2218 Simple String Problem 状压dp

    FZU - 2218Simple String Problem 题目大意:给一个长度为n含有k个不同字母的串,从中挑选出两个连续的子串,要求两个子串中含有不同的字符,问这样的两个子串长度乘积最大是多少 ...

  5. codeforces Diagrams & Tableaux1 (状压DP)

    http://codeforces.com/gym/100405 D题 题在pdf里 codeforces.com/gym/100405/attachments/download/2331/20132 ...

  6. fzu2188 状压dp

    G - Simple String Problem Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%I64d & ...

  7. HDU5816 Hearthstone(状压DP)

    题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5816 Description Hearthstone is an online collec ...

  8. BZOJ-1087 互不侵犯King 状压DP+DFS预处理

    1087: [SCOI2005]互不侵犯King Time Limit: 10 Sec Memory Limit: 162 MB Submit: 2337 Solved: 1366 [Submit][ ...

  9. Codeforces Round #321 (Div. 2) D. Kefa and Dishes 状压dp

    题目链接: 题目 D. Kefa and Dishes time limit per test:2 seconds memory limit per test:256 megabytes 问题描述 W ...

  10. HDUOJ Clear All of Them I 状压DP

    Clear All of Them I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 122768/62768 K (Java/Oth ...

随机推荐

  1. RocketMQ可视化控制台

    中午文档 https://github.com/apache/rocketmq-externals/blob/master/rocketmq-console/doc/1_0_0/UserGuide_C ...

  2. 【spring 注解驱动开发】Spring AOP原理

    尚学堂spring 注解驱动开发学习笔记之 - AOP原理 AOP原理: 1.AOP原理-AOP功能实现 2.AOP原理-@EnableAspectJAutoProxy 3.AOP原理-Annotat ...

  3. commandBinding 的命令

    <Window x:Class="WpfApplication1.Window29" xmlns="http://schemas.microsoft.com/win ...

  4. C++ 矩形交集和并集的面积-离散化

    //离散化,x,y坐标分别按从小到大排序 //离散化 //1.首先分离出所有的横坐标和纵坐标分别按升序存入数组X[ ]和Y[ ]中. //2. 设数组XY[ ][ ].对于每个矩形(x1,y1)(x2 ...

  5. UWP 动画之路径

    xml --------------------------------------------- <Page x:Class="MyApp.MainPage" xmlns= ...

  6. 关于腾讯云redis 无法外网访问的解决方案

    问题简介: 今天购买了一台腾讯云的redis:如图 可是我没有找到 腾讯云提供的外网地址,我该怎么连接呢?百度了一大堆 全部是 在腾讯云服务器上搭建的Redis实例的解决办法.完全不匹配. 开始解决: ...

  7. 【转】Java 开发必会的 Linux 命令

    转自:https://www.cnblogs.com/zhuawang/p/5212809.html 作为一个Java开发人员,有些常用的Linux命令必须掌握.即时平时开发过程中不使用Linux(U ...

  8. 1、Spark简介(Python版)

    此文为个人学习笔记如需系统学习请访问http://dblab.xmu.edu.cn/blog/1709-2/ Spark具有如下几个主要特点:  运行速度快    Spark使用先进的DAG(Dir ...

  9. 理解java调试的工作目录 working directory

    原文链接使用idea或者eclipse进行调试的时候会有Working directory配置: 我们创建工程,IDE会自动创建一个工程目录,假设工程名称为:TestProject,那么在会创建一个目 ...

  10. div 居中显示

    <html lang="en"> <head> <meta charset="UTF-8"> <title>di ...