CF1155F Delivery Oligopoly
题意:给定简单无向图,求一个最小的边集使得这些点是边双,输出方案。n <= 14
解:考虑一个边双肯定是一条一条的链拼起来的。于是每次枚举一条链加上去就行了。
设fs表示点集s形成边双的最小边数。linki,j,s表示点集s能否形成一个i - j的链。link2x,s表示点x和点集s是否直接相连。
上面这些数组都要记录方案,特别地,link2要记录两个方案,为了应对拼上去的链退化成一个点的情况。
#include <bits/stdc++.h>
const int N = ;
struct Edge {
int nex, v;
}edge[N << ]; int tp;
struct Node {
int x, y, t;
Node(int X = , int Y = , int T = ) {
x = X;
y = Y;
t = T;
}
}fr3[N];
int pw[N], cnt[N], f[N], e[N], n, m;
bool link[][][N], link2[][N];
int fr[][][N], fr2[][N], fr22[][N];
inline void add(int x, int y) {
tp++;
edge[tp].v = y;
edge[tp].nex = e[x];
e[x] = tp;
return;
}
void out(int x, int y, int s) {
if(cnt[s] == ) return;
printf("%d %d \n", y + , fr[x][y][s]);
out(x, fr[x][y][s] - , s ^ ( << y));
return;
}
void out3(int s) {
if(cnt[s] == ) return;
int x = fr3[s].x, y = fr3[s].y, t = fr3[s].t;
out(x, y, t);
printf("%d %d \n", x + , fr2[x][s ^ t]);
if(x != y) printf("%d %d \n", y + , fr2[y][s ^ t]);
else printf("%d %d \n", y + , fr22[y][s ^ t]);
out3(s ^ t);
return;
}
int main() {
scanf("%d%d", &n, &m);
for(int i = , x, y; i <= m; i++) {
scanf("%d%d", &x, &y);
add(x, y);
add(y, x);
}
int lm = ( << n) - ; /// lm = 111111...1
for(int i = ; i <= lm; i++) {
cnt[i] = + cnt[i - (i & (-i))];
if(i > ) pw[i] = pw[i >> ] + ;
}
for(int x = ; x < n; x++) {
for(int s = ; s <= lm; s++) {
/// link2[x][s]
if((s >> x) & ) continue;
for(int i = e[x + ]; i; i = edge[i].nex) {
int y = edge[i].v - ;
if((s >> y) & ) {
link2[x][s] = ;
if(!fr2[x][s]) {
fr2[x][s] = y + ;
}
else {
fr22[x][s] = y + ;
break;
}
}
}
}
}
for(int i = ; i < n; i++) {
link[i][i][ << i] = ;
}
for(int s = ; s < lm; s++) {
for(int t1 = s, i; t1; t1 ^= ( << i)) {
i = pw[t1 & (-t1)];
/// i + 1
for(int t2 = s, x; t2; t2 ^= ( << x)) {
x = pw[t2 & (-t2)];
/// f[i][x][s]
if(!link[i][x][s]) continue;
for(int j = e[x + ]; j; j = edge[j].nex) {
int y = edge[j].v - ;
if(((s >> y) & ) == ) {
link[i][y][s | ( << y)] = ;
fr[i][y][s | ( << y)] = x + ;
}
}
}
}
}
memset(f, 0x3f, sizeof(f));
f[] = ;
for(int s = ; s <= lm; s++) {
/// f[s]
for(int t = s & (s - ); t; t = (t - ) & s) {
for(int t1 = t, x; t1; t1 ^= ( << x)) {
x = pw[t1 & (-t1)];
for(int t2 = t, y; t2; t2 ^= ( << y)) {
y = pw[t2 & (-t2)];
/// link[x][y][t] link2[x][s ^ t] link2[y][s ^ t]
if(link[x][y][t] && link2[x][s ^ t] && link2[y][s ^ t] && (x != y || fr22[x][s ^ t])) {
if(f[s] > f[s ^ t] + cnt[t] + ) {
f[s] = f[s ^ t] + cnt[t] + ;
fr3[s] = Node(x, y, t);
}
}
}
}
}
}
printf("%d\n", f[lm]);
out3(lm);
return ;
}
AC代码
CF1155F Delivery Oligopoly的更多相关文章
- Codeforces 1155F Delivery Oligopoly dp(看题解)
看别人写的才学会的... 我们考虑刚开始的一个点, 然后我们枚举接上去的一条一条链, dp[mask]表示当前已经加进去点的状态是mask所需的最少边数. 反正就是很麻烦的一道题, 让我自己写我是写不 ...
- 【Virt.Contest】CF1155(div.2)
CF 传送门 T1:Reverse a Substring 只有本身单调不减的字符串不能转换为字典序更小的字符串.否则肯定会出现 \(s_i>s_{i+1}\) 的情况. 所以只要从头到尾扫一遍 ...
- 《Continuous Delivery》 Notes 1: The problem of delivering software
What is "Deployment pipeline"? A deployment pipeline is an automated implementation of you ...
- zoj 3469 Food Delivery 区间dp + 提前计算费用
Time Limit: 2 Seconds Memory Limit: 65536 KB When we are focusing on solving problems, we usual ...
- 【IOS笔记】Event Delivery: The Responder Chain
Event Delivery: The Responder Chain 事件分发--响应链 When you design your app, it’s likely that you want t ...
- Content Delivery Network
Coding Standards & Best Practices 7 Reasons to use a Content Delivery Network CDN公共库汇总
- codeforces 653D D. Delivery Bears(二分+网络流)
题目链接: D. Delivery Bears time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- zoj 3742 Delivery 好题
Delivery 题目还是自己看吧 - -! 看似图论,实际上是一个考察思维以及数据结构的题. 我们对于先前和向后的边分别进行统计. 对询问离线. 小边按照左端点从大到小排序. 1.对于向后的边,询问 ...
- Repost: Set Delivery Block on SO
If SO is incomplete, then automatically set the delivery block on the SO header. as suggested by ear ...
随机推荐
- 使用 DotNet CLI 创建自定义的 WPF 项目模板
描述 当我们安装完 DotNetCore 3.0 版本的 SDK 后,我们就可以创建基于 DotNetCore 的 WPF 项目模板,通过如下 CLI 可以方便快捷的创建并运行我们的项目: dotne ...
- Android 沉浸式状态栏完美解决方案
现在搜索Android 沉浸式状态栏,真的是一堆一堆,写的特别多,但是真正用的舒服的真没有,在这里自己整理一下开发记录 注意,在使用这个步骤过程之前,请把之前设置的代码注释一下 把布局带有androi ...
- rabbitmq之基本原理及搭建单机环境
1.RabbitMQ基本原理 1.MQ全称Message Queue,是一种分布式应用程序的通信方法,是消费-生产者模型的典型代表,producer向消息队列中不断写入消息,而另一端consumer则 ...
- numpy 基础操作
Numpy 基础操作¶ 以numpy的基本数据例子来学习numpy基本数据处理方法 主要内容有: 创建数组 数组维度转换 数据选区和切片 数组数据计算 随机数 数据合并 数据统计计算 In [1]: ...
- 一条命令解决: sql server 2008 安装提示重启计算机
0.将安装的iso文件解压 1. 使用管理员账户打开 cmd命令行 2.将命令行的路径切换到解压路径下,你应该可以看到setup.exe 3.执行命令 一条命令解决:setup.exe /SkipR ...
- apache ranger源码编译
官方文档 http://ranger.apache.org/quick_start_guide.html Quick Start Guide Build Process 1. Check out th ...
- ckeditor django admin 中使用
ckeditor settings配置 ############ # CKEDITOR # ############ MEDIA_ROOT = os.path.join(BASE_DIR, 'medi ...
- JavaScript match()方法和正则表达式match()
先介绍参数为普通字符串的使用方式,此时match方法的返回值是存放首次匹配内容的数组.如果没有找到匹配结果,返回null.语法结构: 1 str.match(searchvalue)参数解析:(1). ...
- Socket与WebScoket
socket 英文socket的意思是插座,网络中的Socket是一个抽象的接口,可以理解为网络中连接的两端.通常被叫做套接字接口,其意义在对传输层进行封装屏蔽了传输层的复杂性.它并不是一个协议,是为 ...
- Nginx+Django-Python+BPMN-JS的整合工作流实战项目
前言 找一个好用的画图工具真心不容易,Activiti 工作流自带的 Web 版画图工具,外表挺华丽,其实使用起来各种拧巴:Eclipse 的 Activiti 画图插件,对于相对复杂的流程也是很不友 ...