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 ...
随机推荐
- 笔记之Cyclone IV第一卷第三章器件中的存储器模块
嵌入式存储器结构由一列列 M9K 存储器模块组成,通过对这些 M9K 存储器模块进行配置,可以实现各种存储器功能,例如:RAM.移位寄存器. ROM 以及FIFO 缓冲器. M9K 存储器模块支持以下 ...
- BAAS
http://blogs.embarcadero.com/sarinadupont/category/baas-tutorials/?cid=701G0000000vH0A&elq=51f98 ...
- windows无效字符名导致的错误及解决办法
今天用file_put_content($fileName,$data)产生错误:内容如下: Warning: file_put_contents(images/7d5636992a7395f9174 ...
- CImage类的介绍与使用
CImage类的介绍与使用 程序代码下载处:http://download.csdn.net/source/2098910 下载处:http://hi.baidu.com/wangleitongxin ...
- 数据库基础学习3-T-SQL语句
一.语句操作的基本方法 1.选中执行. 2.注释的方法‘--’. 二.数据类型 整数:int,bigint,smallint 小数:float,decimal(长度,精度) 字符:char(n),va ...
- javascript每日一练(十四)——弹性运动
一.弹性运动 运动原理:加速运动+减速运动+摩擦运动: <!doctype html> <html> <head> <meta charset="u ...
- 基于visual Studio2013解决C语言竞赛题之0801信息输出
题目
- 在vc中使用xtremetoolkit界面库-----安装及环境配置
近期想用一下xtremetoolkitPro界面库.网上的使用教程资源也不多,当中着实遇到了很多的困难,毕竟是首次使用. 首先当然是配置发开环境了: 我使用的是vc6.0+xtremetoolkitP ...
- WCF技术剖析之十一:异步操作在WCF中的应用(下篇)
原文:WCF技术剖析之十一:异步操作在WCF中的应用(下篇) 说完了客户端的异步服务调用(参阅WCF技术剖析之十一:异步操作在WCF中的应用(上篇)),我们在来谈谈服务端如何通过异步的方式为服务提供实 ...
- Dynamic Pivot table wizard SQL Server
原文 http://www.gyurcit.hu/pivot.html Dynamic Pivot table wizard This stored procedure generate dynami ...