状态压缩codeforces 11 D
n个点m条边
m条边
求有几个环;
#pragma comment(linker, "/STACK:102400000,102400000")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
using namespace std; typedef long long LL;
typedef pair<int,int> PII; const int N=; LL ans;
int n,m,low;
LL dp[][N];
bool adj[N][N]; int main()
{
scanf("%d%d",&n,&m); for(int i=;i<m;i++)
{
int a,b; scanf("%d%d",&a,&b);
a--; b--;
adj[a][b]=adj[b][a]=;
} for(int i=;i<n;i++) dp[<<i][i]=; for(int i=;i<(<<n);i++)
{
int st=n+,cnt=;
for(int j=;j<n;j++) //这个状态中有多少个点
if(i&(<<j))
{
st=min(st,j); cnt++;
} for(int j=;j<n;j++)
if(dp[i][j])
{
if(adj[j][st]&&cnt>=) //点>=三 又要能回去
{
ans+=dp[i][j];
} for(int k=;k<n;k++)
if(adj[j][k]&&k>st) //st是最小的点
{
if((i&(<<k))==) dp[i^(<<k)][k]+=dp[i][j];
}
}
} cout<<ans/<<endl; return ;
}
状态压缩codeforces 11 D的更多相关文章
- dp + 状态压缩 - Codeforces 580D Kefa and Dishes
Kefa and Dishes Problem's Link Mean: 菜单上有n道菜,需要点m道.每道菜的美味值为ai. 有k个规则,每个规则:在吃完第xi道菜后接着吃yi可以多获得vi的美味值. ...
- Codeforces C. A Simple Task(状态压缩dp)
题目描述: A Simple Task time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- codeforces B - Preparing Olympiad(dfs或者状态压缩枚举)
B. Preparing Olympiad You have n problems. You have estimated the difficulty of the i-th one as inte ...
- codeforces 713A A. Sonya and Queries(状态压缩)
题目链接: A. Sonya and Queries time limit per test 1 second memory limit per test 256 megabytes input st ...
- codeforces 425B Sereja and Table(状态压缩,也可以数组模拟)
题目 给出一个n*m的01矩阵, 让你最多改变k个里面的值(0变1,1变0), 使得0.1的连通分量是矩阵.输出最少步数 1 ≤ n, m ≤ 100; 1 ≤ k ≤ 10 题解: 如果01连通分量 ...
- Codeforces 4538 (状态压缩dp)Little Pony and Harmony Chest
Little Pony and Harmony Chest 经典状态压缩dp #include <cstdio> #include <cstring> #include < ...
- Codeforces Round #235 (Div. 2) D. Roman and Numbers (数位dp、状态压缩)
D. Roman and Numbers time limit per test 4 seconds memory limit per test 512 megabytes input standar ...
- [CodeForces 11D] A Simple Task - 状态压缩入门
状态压缩/Bitmask 在动态规划问题中,我们会遇到需要记录一个节点是否被占用/是否到达过的情况.而对于一个节点数有多个甚至十几个的问题,开一个巨型的[0/1]数组显然不现实.于是就引入了状态压缩, ...
- SRM 513 2 1000CutTheNumbers(状态压缩)
SRM 513 2 1000CutTheNumbers Problem Statement Manao has a board filled with digits represented as St ...
随机推荐
- CF687C. The Values You Can Make[背包DP]
C. The Values You Can Make time limit per test 2 seconds memory limit per test 256 megabytes input s ...
- C# Enum 进行逻辑运算
Enum定义 enum 全称(Enumeration),即一种由一组称为枚举数列表的命名常量组成的独特类型. 通常情况下,最好是在命名空间內直接定义 enum,以便该命名空间中所有的类都能够同样方便地 ...
- JavaScript RegExp 对象
JavaScript RegExp 对象 RegExp 对象用于规定在文本中检索的内容. 什么是 RegExp? RegExp 是正则表达式的缩写. 当您检索某个文本时,可以使用一种模式来描述要检索的 ...
- [No00000C]Word快捷键大全 Word2013/2010/2007/2003常用快捷键大全
Word对于我们办公来说,是不可缺少的办公软件,因为没有它我们可能无法进行许多任务.所以现在的文员和办公室工作的人,最基础的就是会熟悉的使用Office办公软件.在此,为提高大家Word使用水平,特为 ...
- 理解android.intent.action.MAIN 与 android.intent.category.LAUNCHER
刚才看了一下sundy的视频<LLY110426_Android应用程序启动>,里面讲到luncher这个activity通过获取应用程序信息来加载应用程序,显示给用户,其中就是通过一个应 ...
- 对于大量left join 的表查询,可以在关键的 连接节点字段上创建索引。
对于大量left join 的表查询,可以在关键的 连接节点字段上创建索引. 问题: 大量的left join 怎么优化 select a.id,a.num,b.num,b.pcs,c.num, c. ...
- HTML 学习笔记 CSS3 (2D Matrix)
Matrix 矩阵 那么什么是矩阵呢? 矩阵可以理解为方阵,只不过 平时方阵里面站着人 矩阵中是数值: CSS3中的矩阵: css3中的矩阵指的是一个方法,书写为matrix() 和 matrix3d ...
- java的string常用操作
import java.util.*; public class Demo3 { public static void main(String args[]){ String str = " ...
- js判断是否在微信浏览器中打开
用JS来判断,无论是android 还是iphone,ipad 都可以 function is_weixn(){ var ua = navigator.userAgent.toLowerCase(); ...
- 51nod lyk与gcd
1678 lyk与gcd 基准时间限制:2 秒 空间限制:131072 KB 分值: 80 难度:5级算法题 这天,lyk又和gcd杠上了.它拥有一个n个数的数列,它想实现两种操作. 1:将 ai ...