状压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 ...
随机推荐
- android中RelativeLayout无法填充ScrollView布局的问题
ScrollView是解决布局过长的情况下使用,一遍其下面会有个顶部布局,我项目里面是RelativeLayout,但是RelativeLayout无论设置 android:layout_height ...
- POJ 2656 Unhappy Jinjin
#include <stdio.h> int main() { ) { int i, n; ; scanf("%d", &n); ) break; ; i &l ...
- jsp容易混淆的知识点
1.在使用的时候可以使用${pageContext.request.contextPath},也同时可以使用<%=request.getContextPath()%>达到同样的效果,同时, ...
- Chapter 2 Open Book——24
Mike kept up a string of complaints on the way to building four. mike去教学楼的路上一直嘀咕抱怨着. Once inside the ...
- Hack写法
文章来源: http://www.w3cplus.com/css/create-css-browers-hacks 条件注释:http://www.w3cplus.com/create-an-ie-o ...
- 印象烟大PPT大赛
下面为获奖人员 王志恒一等奖 姜云飞.任子仪二等奖 田正相,庄棫麟,陈德昊三等奖.
- CentOS postgresql9.4
yum install http://yum.postgresql.org/9.4/redhat/rhel-6-x86_64/pgdg-redhat94-9.4-1.noarch.rpm Once t ...
- BestCoder Round #86 A B C
这次BC终于不像上次一样惨烈 终于A了三题…… 终测ing…… 发一波题解…… A.Price List A题十分无脑 只要把所有数加起来存到sum里 询问的时候大于sum输出1 否则输出0就行了…… ...
- html5 让IE6,7支持HTML5语义化标签的文件
https://github.com/aFarkas/html5shiv/blob/master/src/html5shiv.js 只要应用这个js就行了
- Gentoo安装详解(二)-- 编译内核
编译内核: 安装内核源码: 选择内核:如gentoo-sources emerge gentoo-sources ls -l /usr/src/linux 手动编译内核: cd /usr/src/li ...