状压dp找寻环的个数 Codeforces Beta Round #11 D
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的更多相关文章
- Codeforces Beta Round #11 A. Increasing Sequence 贪心
A. Increasing Sequence 题目连接: http://www.codeforces.com/contest/11/problem/A Description A sequence a ...
- Codeforces Beta Round #11 B. Jumping Jack 数学
B. Jumping Jack 题目连接: http://www.codeforces.com/contest/11/problem/B Description Jack is working on ...
- 【BZOJ1076】[SCOI2008] 奖励关(状压DP)
点此看题面 大致题意:总共有\(n\)个宝物和\(k\)个回合,每个回合系统将随机抛出一个宝物(抛出每个宝物的概率皆为\(1/n\)),吃掉一个宝物可以获得一定的积分(积分可能为负),而吃掉某个宝物有 ...
- codeforces Diagrams & Tableaux1 (状压DP)
http://codeforces.com/gym/100405 D题 题在pdf里 codeforces.com/gym/100405/attachments/download/2331/20132 ...
- Codeforces Round #531 (Div. 3) F. Elongated Matrix(状压DP)
F. Elongated Matrix 题目链接:https://codeforces.com/contest/1102/problem/F 题意: 给出一个n*m的矩阵,现在可以随意交换任意的两行, ...
- codeforces 454 D. Little Pony and Harmony Chest(状压dp)
题目链接:http://codeforces.com/contest/454/problem/D 题意:给定一个序列a, 求一序列b,要求∑|ai−bi|最小.并且b中任意两数的最大公约数为1. 题解 ...
- Codeforces 1225G - To Make 1(bitset+状压 dp+找性质)
Codeforces 题目传送门 & 洛谷题目传送门 还是做题做太少了啊--碰到这种题一点感觉都没有-- 首先我们来证明一件事情,那就是存在一种合并方式 \(\Leftrightarrow\) ...
- Codeforces 79D - Password(状压 dp+差分转化)
Codeforces 题目传送门 & 洛谷题目传送门 一个远古场的 *2800,在现在看来大概 *2600 左右罢( 不过我写这篇题解的原因大概是因为这题教会了我一个套路罢( 首先注意到每次翻 ...
- Codeforces Gym 100015F Fighting for Triangles 状压DP
Fighting for Triangles 题目连接: http://codeforces.com/gym/100015/attachments Description Andy and Ralph ...
随机推荐
- icon的使用
在前端页面设计时,不免使用的就是图标,下面就我使用图标icon分享一下经验 1.icon插件,现在比较好的是bootstrap自带的,fontawesome,链接地址:http://fontaweso ...
- win7远程连接ubuntu14.04.1桌面
sudo apt-get install xdrp sudo apt-get install vnc4server tightserver sudo apt-get install xfce4 ech ...
- 2、创建File类对象
既然是内置类,那么我们创建对象时自然要看它封装好的构造函数咯,由下图的4中构造函数我们可知有4种办法来创建File对象 具体代码如下 public class Demo { public static ...
- ubuntu 禁用快捷键
System Settings > Keyboard > Shortcuts 点击要禁用的快捷键,按键盘"Backspace"键,就可以禁用了
- 一行一行分析JQ源码学习笔记-03
rquickExpr: <p>aaaa 或 #div1 rsingieTag: rmsPrefix :/-ms-/ 是否是ie rdashAlpha = 转大小写 数字 (-2 ...
- dplyr 数据操作 统计描述(summarise)
在R中,summary()是一个基础包中的重要统计描述函数,同样的在dplyr中summarise()函数也可以对数据进行统计描述. 不同的是summarise()更加的灵活多变,下面来看下summa ...
- hdu_5862_Counting Intersections(扫描线)
题目链接:hdu_5862_Counting Intersections 题意: 给你与坐标轴平行的线段,问你交点数 题解: 实质就是扫描线,这里我用树状数组来记录,所有线段按X坐标排序,遇到横线段的 ...
- MongoDB索引(一)
原文地址 一.介绍 我们已经很清楚索引会提高查询效率.如果没有索引,MongoDB必须对全部集合进行扫描,即,扫描集合中每条文档以选择那些符合查询条件的文档.对查询来说如果存在合适的索引,则Mongo ...
- OpenCL( 一)
#include <CL/cl.h> #include <iostream> #include <string> #include <fstream> ...
- CDOJ 1270 Playfair(模拟)
题目链接 Playfair is a kind of substitution cipher.And the encryption role is simple.In general,there ar ...