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 ...
随机推荐
- C# 7.0
C# 7.0 本文参考Roslyn项目中的Issue:#118. 1. C# 7.0 新特性1: 基于Tuple的“多”返回值方法 2. C# 7.0 新特性2: 本地方法 3. C# 7.0 新特性 ...
- const关键字详解
const在函数前与函数后的区别 一 const基础 如果const关键字不涉及到指针,我们很好理解,下面是涉及到指针的情况: int b = 500; ...
- stm32中断优先级
VIC_IRQChannelPreemptionPriority:先占优先级 NVIC_IRQChannelSubPriority:从优先级 高先占优先级中断可以打断低先占优先级的中断,即可中断嵌套 ...
- 【开源框架】Android之史上最全最简单最有用的第三方开源库收集整理,有助于快速开发,欢迎各位网友补充完善
链接地址:http://www.tuicool.com/articles/jyA3MrU 时间 2015-01-05 10:08:18 我是程序猿,我为自己代言 原文 http://blog.cs ...
- HEVC码率控制浅析——HM代码阅读之一
HM的码率控制提案主要参考如下三篇:K0103,M0036,M0257.本文及后续文章将基于HM12.0进行讨论,且首先仅讨论K0103对应的代码,之后再陆续补充M0036,M0257对应的代码分析, ...
- AT&T汇编
AT&T汇编和8086汇编语言虽然两者很相似,但是还是不能根据8086的语法规则来读AT&T汇编的吧,所以还是要看看AT&T汇编的语法规则,因为在读内核代码时,跟硬件打交道的部 ...
- Codeforces Round #189 (Div. 2)
题目地址:http://codeforces.com/contest/320 第一题:基本题,判断mod 1000,mod 100.,mod 10是不是等于144.14.1,直到为0 代码如下: #i ...
- [置顶] android 自定义TextView
系统自带的控件TextView有时候没满一行就换行了,为了解决这个问题,自定义了一个TextView,只有一行显示不完全的情况下才会去换行显示,代码如下: package com.open.textv ...
- #AOS应用基础平台# 添加了用户自己定义快捷菜单在平铺布局下的用户自己定义排序管理
#AOS开发平台# 添加了用户自己定义快捷菜单在平铺布局下的用户自己定义排序管理.
- PHP - 遍历文件夹下的所有文件名
/** * * 函数名:myreaddir($dir) * 作用:读取目录所有的文件名 * 参数:$dir 目录地址 * 返回值:文件名数组 * * */ function myreaddir($di ...