hdu 4687 Boke and Tsukkomi
Dancing link twice.
Find the maximum combination numbers in the first time.
Enumerate each node, dancing.
If the new result is not optimaze, then push it into ans.
#include <cstdio>
#include <vector>
#include <bitset>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;
const int M = 200; // exact
struct dancing {
#define dfor(c, a, b) for (int c = a[b]; c != b; c = a[c])
static const int row_size = 220, column_size = 220,
total_size = row_size*column_size;
typedef int row[row_size],
column[column_size],
total[total_size];
total l, r, u, d, in_column, in_row;
bitset<50> use;
column s;
int index, current_row, row_head, limit, mx, rn;
void init(int n, int m) {
rn = m;
limit = 0;
index = ++n;
for (int i = 0; i < n; i++) {
l[i] = (i - 1 + n) % n;
r[i] = (i + 1) % n;
u[i] = d[i] = i;
}
current_row = 0;
memset(s, 0, sizeof(s));
use = ans = bitset<50>();
mx = -1;
}
void push(int i, int j) {
i++; j++;
if (current_row < i) {
row_head = l[index] = r[index] = index;
current_row = i;
}
l[index] = l[row_head]; r[index] = row_head;
r[l[row_head]] = index; l[row_head] = index;
u[index] = u[j]; d[index] = j;
d[u[j]] = index; u[j] = index;
s[j]++;
in_row[index] = i;
in_column[index++] = j;
}
void exactly_remove(int c) {
l[r[c]] = l[c];
r[l[c]] = r[c];
dfor(i, d, c) {
dfor (j, r, i) {
u[d[j]] = u[j];
d[u[j]] = d[j];
s[in_column[j]]--;
}
}
}
void exactly_resume(int c) {
dfor(i, u, c) {
dfor(j, l, i) {
s[in_column[j]]++;
d[u[j]] = u[d[j]] = j;
}
}
r[l[c]] = l[r[c]] = c;
}
bool exactly_dance(int step = 0) {
limit = max(limit, step);
if (limit == mx) return 1;
if (!r[0]) return 0;
int has = rn-use.count();
if (!has || step+has < limit || step+has < mx) return 0;
int x = r[0];
dfor(i, r, 0) {
if (s[i] && s[i] < s[x] || !s[x]) {
x = i;
}
}
exactly_remove(x);
dfor(i, d, x) {
use[in_column[i]] = 1;
dfor(j, r, i) {
exactly_remove(in_column[j]);
}
if (exactly_dance(step + 1)) {
return 1;
}
dfor(j, l, i) {
exactly_resume(in_column[j]);
}
use[in_column[i]] = 0;
}
exactly_resume(x);
return 0;
}
#undef dfor
};
dancing dlx; struct com {
int b, t;
void input() {
scanf("%d%d", &b, &t);
}
} c[M];
int n, m, g[M][50]; int main() {
for ( ; ~scanf("%d%d", &n, &m); ) {
memset(g, 0, sizeof(g));
dlx.init(n, m);
for (int i = 0; i < m; i++) {
c[i].input();
if (c[i].b > c[i].t) swap(c[i].b, c[i].t);
int b = c[i].b, t = c[i].t;
g[i][b] = g[i][t] = 1;
dlx.push(i, b-1);
dlx.push(i, t-1);
}
dlx.exactly_dance();
int limit = dlx.limit;
vector<int> ans;
int ban[M] = {0};
for (int i = 0; i < m; i++) {
int tm = m;
memset(ban, 0, sizeof(int)*m);
for (int j = 0; j < m; j++) if (i != j)
if (g[j][c[i].b] || g[j][c[i].t]) {
ban[j] = 1;
tm--;
}
dlx.init(n, tm);
for (int j = 0; j < m; j++) if (!ban[j]) {
dlx.push(j, c[j].b-1);
dlx.push(j, c[j].t-1);
}
dlx.mx = limit;
dlx.exactly_dance();
if (limit != dlx.limit) ans.push_back(i+1);
}
printf("%d\n", (int)ans.size());
if (!ans.size()) puts("");
else for (int i = 0; i < ans.size(); i++)
printf("%d%c", ans[i], i < ans.size()-1? ' ': '\n');
}
return 0;
}
hdu 4687 Boke and Tsukkomi的更多相关文章
- HDU 4687 Boke and Tsukkomi (一般图匹配带花树)
Boke and Tsukkomi Time Limit: 3000/3000 MS (Java/Others) Memory Limit: 102400/102400 K (Java/Othe ...
- HDU 4687 Boke and Tsukkomi 一般图匹配,带花树,思路,输出注意空行 难度:4
http://acm.hdu.edu.cn/showproblem.php?pid=4687 此题求哪些边在任何一般图极大匹配中都无用,对于任意一条边i,设i的两个端点分别为si,ti, 则任意一个极 ...
- HDU 4687 Boke and Tsukkomi (一般图最大匹配)【带花树】
<题目链接> 题目大意: 给你n个点和m条边,每条边代表两点具有匹配关系,问你有多少对匹配是冗余的. 解题分析: 所谓不冗余,自然就是这对匹配关系处于最大匹配中,即该匹配关系有意义.那怎样 ...
- HDOJ 4687 Boke and Tsukkomi 一般图最大匹配带花树+暴力
一般图最大匹配带花树+暴力: 先算最大匹配 C1 在枚举每一条边,去掉和这条边两个端点有关的边.....再跑Edmonds得到匹配C2 假设C2+2==C1则这条边再某个最大匹配中 Boke and ...
- Hdu4687 Boke and Tsukkomi
Boke and Tsukkomi Time ...
- HDU-4687 Boke and Tsukkomi 带花树,枚举
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4687 题意:给一个无向图,求所有的最大匹配的情况所不包含的边.. 数据比较小,直接枚举边.先求一次最大 ...
- hdu 4687 带花树匹配
其实吧,思路挺简单的,只不过昨天刚学,还有一些东西不太了解,然后就23333333... 吃晚饭回来就A了,我是有多傻啊,这么题都A不掉,不能忍啊... 我们可以先求出哪些边是可能存在于最大匹配中的, ...
- 二分图水一波~~~~d带你飞
Current Time: 2016-03-11 17:45:36 Contest Type: Public Start Time: 2016-03-04 13:00:00 Contest Statu ...
- [kuangbin带你飞]专题十 匹配问题
A-L 二分匹配 M-O 二分图多重匹配 P-Q 二分图最大权匹配 R-S 一般图匹配带花树 模板请自己找 ID Origin Title 61 / 72 Problem A HD ...
随机推荐
- POJ 1861 Network (模版kruskal算法)
Network Time Limit: 1000MS Memory Limit: 30000K Total Submissions: Accepted: Special Judge Descripti ...
- Ubuntu上搭建DokuWiki
1.准备工作 1) 安装Apache sudo apt-get install apache2 2)在浏览器中输入http://localhost 如果现实It works则说明Apache安装成功, ...
- 基于visual Studio2013解决C语言竞赛题之0419误差控制
题目 解决代码及点评 /************************************************************************/ /* 19 ...
- CMake入门指南
原文地址:http://www.cnblogs.com/sinojelly/archive/2010/05/22/1741337.html CMake是一个比make更高级的编译配置工具,它可以根据不 ...
- OGR SQL
The OGRDataSource supports executing commands against a datasource via the OGRDataSource::ExecuteSQL ...
- 关于libgdx中UI控件的旋转和缩放的备忘
最近遇到这样一个问题,定义了一个ImageButton后,想对按钮进行下旋转,结果setRotation(-90f),不起作用.后来在官网上找到了原因 关于UI控件的旋转 缩放官网上有这样一段话(链接 ...
- hdu 1528 Card Game Cheater ( 二分图匹配 )
题目:点击打开链接 题意:两个人纸牌游戏,牌大的人得分.牌大:2 < 3 < 4 < 5 < 6 < 7 < 8 < 9 < T < J < ...
- Vim 使用设置
转自:http://www.cnblogs.com/end/archive/2012/06/01/2531147.html Vim 作为最好用的文本编辑器之一,使用vim来编文档,写代码实在是很惬意的 ...
- javascript:设置URL参数的方法,适合多条件查询
适用场景:多条件查询情况,如下图所示: 通过设置URL参数,再结合数据源控件设置的RUL参数,就能进行简单的多条件查询了. javascript函数: <mce:script type=&quo ...
- dsdfdsfd
aibang.com/show/1816725179-1268699976/product/7069113.html aibang.com/show/1816725179-1268699976/pro ...