题意:给定简单无向图,求一个最小的边集使得这些点是边双,输出方案。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的更多相关文章

  1. Codeforces 1155F Delivery Oligopoly dp(看题解)

    看别人写的才学会的... 我们考虑刚开始的一个点, 然后我们枚举接上去的一条一条链, dp[mask]表示当前已经加进去点的状态是mask所需的最少边数. 反正就是很麻烦的一道题, 让我自己写我是写不 ...

  2. 【Virt.Contest】CF1155(div.2)

    CF 传送门 T1:Reverse a Substring 只有本身单调不减的字符串不能转换为字典序更小的字符串.否则肯定会出现 \(s_i>s_{i+1}\) 的情况. 所以只要从头到尾扫一遍 ...

  3. 《Continuous Delivery》 Notes 1: The problem of delivering software

    What is "Deployment pipeline"? A deployment pipeline is an automated implementation of you ...

  4. zoj 3469 Food Delivery 区间dp + 提前计算费用

    Time Limit: 2 Seconds      Memory Limit: 65536 KB When we are focusing on solving problems, we usual ...

  5. 【IOS笔记】Event Delivery: The Responder Chain

    Event Delivery: The Responder Chain  事件分发--响应链 When you design your app, it’s likely that you want t ...

  6. Content Delivery Network

    Coding Standards & Best Practices 7 Reasons to use a Content Delivery Network CDN公共库汇总

  7. codeforces 653D D. Delivery Bears(二分+网络流)

    题目链接: D. Delivery Bears time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  8. zoj 3742 Delivery 好题

    Delivery 题目还是自己看吧 - -! 看似图论,实际上是一个考察思维以及数据结构的题. 我们对于先前和向后的边分别进行统计. 对询问离线. 小边按照左端点从大到小排序. 1.对于向后的边,询问 ...

  9. Repost: Set Delivery Block on SO

    If SO is incomplete, then automatically set the delivery block on the SO header. as suggested by ear ...

随机推荐

  1. RSA签名和验签Util

    目录 1.DigitalSign类 2.CryptException异常类 3.加签示例 1.DigitalSign类 import org.apache.commons.codec.binary.B ...

  2. Java 单例(Singleton)模式

    一.什么是单例模式: 单例模式是一种确保了一个类只有一个实例,而且自行实例化并向整个系统提供这个实例.被实例化的类称为单例类. 二.单例模式的特点: 单例类只有一个实例. 单例类必须自行创建自己唯一的 ...

  3. hadoop集群的搭建

    hadoop集群的搭建 1.ubuntu 14.04更换成阿里云源 刚刚开始我选择了nat模式,所有可以连通网络,但是不能ping通,我就是想安装一下mysql,因为安装手动安装mysql太麻烦了,然 ...

  4. Play vue.js with constant value in SailsJS

    SailsJS supplies a utility module called parasails, which defines two elements, <ajax-form> an ...

  5. python3 字符串/列表/元组(str/list/tuple)相互转换方法及join()函数的使用

    在抓取网络数据的时候,有时会用正则对结构化的数据进行提取,比如 href="https://www.1234.com"等.python的re模块的findall()函数会返回一个所 ...

  6. 获取OlapConnection连接

    目录: 1.获取org.olap4j.OlapConnection对象 2.获取mondrian.olap.Connection对象 一.org.olap4j.OlapConnection对象 说明: ...

  7. 「技巧」如何快速安装 Sketch 插件

    Sketch拥有强大丰富的插件,但是这些插件天各一方,四处查找下载地址非常麻烦.这里提供一个技巧,通过一个入口可以安装各种插件,基本涵盖了市面上所有靠谱的插件. 准备 Sketch54 Runner ...

  8. slice 与 splice 的区别

    slice: 定义一个数组:let b = ['a','b','c','d','e'] b:["a", "b", "c", "d& ...

  9. 一个简单的以太坊合约让imtoken支持多签

    熟悉比特币和以太坊的人应该都知道,在比特币中有2种类型的地址,1开头的是P2PKH,就是个人地址,3开头的是P2SH,一般是一个多签地址.所以在原生上比特币就支持多签.多签的一个优势就是可以多方对一笔 ...

  10. 从Java小白到阿里巴巴工程师,回顾我两年来的学习经历

    添加描述