http://codeforces.com/problemset/problem/11/D

题目大意:给你n个点,m条边,找该图中有几个换

思路:定义dp[i][j]表示i是圈的集合,j表示该集合的终点,定义起点为这些走过的点里面最小的

//看看会不会爆int!数组会不会少了一维!
//取物问题一定要小心先手胜利的条件
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define haha printf("haha\n")
const int maxn = ;
LL dp[ << maxn][maxn + ];
int a[maxn + ][maxn + ];
int n, m; void get_min(int val, int &cnt, int &st){
int pos = ;
while (val){
if (val & ) st = min(st, pos), cnt++;
val >>= ;
pos++;
}
}
///定义dp[i][j]表示i是圈的集合,j表示该集合的终点,定义起点为这些走过的点里面最小的
int main(){
cin >> n >> m;
for (int i = ; i <= m; i++){
int u, v; scanf("%d%d", &u, &v);
u--, v--;
a[u][v] = a[v][u] = ;
}
LL ans = ;
for (int i = ; i < n; i++) dp[ << i][i] = ;///初始化
for (int i = ; i < ( << n); i++){
int cnt = , st = n;
get_min(i, cnt, st);
for (int j = ; j < n; j++){
if (dp[i][j]){///目前集合为i,终点为j。而且根据放入集合的顺序,j必然是在i集合里面的
if (a[st][j] && cnt >= ){///放入集合的最终的终点一定得是在st的旁边。否则会将形不成环的放入ans中
ans += dp[i][j];
}
for (int k = st + ; k < n; k++){///放入终点大于st的。根据定义st必然为最小的起点。
///然后k<st的已经在更小的状态中全部都计算过了
if (a[j][k] && !(i & (1 << k))){
dp[i | (1 << k)][k] += dp[i][j];
}
}
}
}
}
/*haha;
for(int i = 0; i < n; i++){
for (int j = 0; j < (1 << n); j++){
printf("%lld ", dp[j][i]);
}
cout << endl;
}*/
cout << ans / << endl;
return ;
}

状压dp找寻环的个数 Codeforces Beta Round #11 D的更多相关文章

  1. Codeforces Beta Round #11 A. Increasing Sequence 贪心

    A. Increasing Sequence 题目连接: http://www.codeforces.com/contest/11/problem/A Description A sequence a ...

  2. Codeforces Beta Round #11 B. Jumping Jack 数学

    B. Jumping Jack 题目连接: http://www.codeforces.com/contest/11/problem/B Description Jack is working on ...

  3. 【BZOJ1076】[SCOI2008] 奖励关(状压DP)

    点此看题面 大致题意:总共有\(n\)个宝物和\(k\)个回合,每个回合系统将随机抛出一个宝物(抛出每个宝物的概率皆为\(1/n\)),吃掉一个宝物可以获得一定的积分(积分可能为负),而吃掉某个宝物有 ...

  4. codeforces Diagrams & Tableaux1 (状压DP)

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

  5. Codeforces Round #531 (Div. 3) F. Elongated Matrix(状压DP)

    F. Elongated Matrix 题目链接:https://codeforces.com/contest/1102/problem/F 题意: 给出一个n*m的矩阵,现在可以随意交换任意的两行, ...

  6. codeforces 454 D. Little Pony and Harmony Chest(状压dp)

    题目链接:http://codeforces.com/contest/454/problem/D 题意:给定一个序列a, 求一序列b,要求∑|ai−bi|最小.并且b中任意两数的最大公约数为1. 题解 ...

  7. Codeforces 1225G - To Make 1(bitset+状压 dp+找性质)

    Codeforces 题目传送门 & 洛谷题目传送门 还是做题做太少了啊--碰到这种题一点感觉都没有-- 首先我们来证明一件事情,那就是存在一种合并方式 \(\Leftrightarrow\) ...

  8. Codeforces 79D - Password(状压 dp+差分转化)

    Codeforces 题目传送门 & 洛谷题目传送门 一个远古场的 *2800,在现在看来大概 *2600 左右罢( 不过我写这篇题解的原因大概是因为这题教会了我一个套路罢( 首先注意到每次翻 ...

  9. Codeforces Gym 100015F Fighting for Triangles 状压DP

    Fighting for Triangles 题目连接: http://codeforces.com/gym/100015/attachments Description Andy and Ralph ...

随机推荐

  1. 通过SvcUtil.exe 生成 Wcf 客户端代理

    WCF服务调用通过两种常用的方式:一种是借助代码生成工具SvcUtil.exe或者添加服务引用的方式,一种是通过ChannelFactory直接创建服务代理对象进行服务调用. SvcUtil.exe ...

  2. Linux关闭selinux

    最近在折腾Linux服务器,配置环境时,安装php的一个拓展,明明编译成功了,就是加载不进去,phpinfo不显示,查看错误日志是显示加载失败,没权限==,配置ftp程序也会有意想不到的问题,搞了好久 ...

  3. Flood-it!

    Flood-it! 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4127/http://acm.split.hdu.edu.cn/showproble ...

  4. 使用PhotoShop

    详细请看:http://blog.sina.com.cn/s/blog_73dc36510101ahim.html

  5. cloudeye的实现

    难点在于DNS server的搭建,然而非常简单,安装dnslib就有DNS server:zoneresolver.py,稍作修改即可使用   # -*- coding: utf-8 -*- fro ...

  6. GOPS 2016全球运维大会 • 北京站概况

    GOPS 2016全球运维大会上海站已圆满落幕,错过上海站的朋友或许会感到一些遗憾,但是不用担心,在12月16日,GOPS 2016全球运维大会 • 北京站将隆重召开,错过上海在的朋友可以赶上北京站哦 ...

  7. Spring Security(09)——Filter

    目录 1.1     Filter顺序 1.2     添加Filter到FilterChain 1.3     DelegatingFilterProxy 1.4     FilterChainPr ...

  8. linux文件系统拓展属性

    在研究GlusterFS中,发现GlusterFS使用了文件系统的Extended Attributes,中文可以称之为文件系统扩展属性.由于资料比较少,中文资料更少,因此把记录几点Extended ...

  9. hdfs zkfc –formatZK 之HadoopIllegalArgumentException: Bad argument: –formatZK

    HadoopIllegalArgumentException: Bad argument: –formatZK从某文档中拷贝的命令,粘贴过来使用的,“–formatZK”有问题解决方法:手工输入此命令 ...

  10. 设计模式 装饰模式(Decorator)

    设计模式 装饰模式(Decorator) @author ixenos 装饰模式是什么 1.装饰模式以对客户端透明的方式对象的功能,是继承关系的一个替代方案,但装饰模式可以在不创造更多子类的情况下,对 ...