题意:给定简单无向图,求一个最小的边集使得这些点是边双,输出方案。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. flex页面布局练习--知乎

    采用flexbox弹性容器 在手机端进行页面布局 样本地址: http://tpl.zhuamimi.cn/%E6%89%8B%E6%9C%BA%E7%AB%AF%E9%A1%B5%E9%9D%A2- ...

  2. 微信小程序 canvas 文字自动换行

    Page({ drawCanvas: function(ctx) {// 地址 ctx.setFontSize() ctx.setFillStyle('#9E7240') ctx.textAlign= ...

  3. Odoo 10的Linux安装

    CentOS7安装Odoo10流程如下一.更新系统#yum clean all#yum update 二.安装 PostgreSQL 1.安装数据库#yum install postgresql po ...

  4. C#中try catch finally 用法

    1.将预见可能引发异常的代码包含在try语句块中. 2.如果发生了异常,则转入catch的执行. catch有几种写法: catch  这将捕获任何发生的异常. catch(Exception e)  ...

  5. arcgis api 3.x for js 实现克里金插值渲染图不依赖 GP 服务(附源码下载)

    前言 关于本篇功能实现用到的 api 涉及类看不懂的,请参照 esri 官网的 arcgis api 3.x for js:esri 官网 api,里面详细的介绍 arcgis api 3.x 各个类 ...

  6. 生鲜配送管理系统_升鲜宝V2.0 小标签打印功能说明_15382353715

    小标签打印说明 小标签打印可以打印本系统的订单商品数量,也可以把外部的订单商品导入本系统进行打印. 打印本系统中的订单商品操作说明 1.1    界面说明 1.2     查询条件 1.2.1     ...

  7. OpenCL中三种内存创建image的效率对比

    第一种:使用ION: cl_mem_ion_host_ptr ion_host_ptr1; ion_host_ptr1.ext_host_ptr.allocation_type = CL_MEM_IO ...

  8. 小米平板6.0系统如何无ROOT激活xposed框架的步骤

    在较多企业的引流,或业务操作中,基本上都需要使用安卓的黑高科技术Xposed框架,近期,我们企业购买了一批新的小米平板6.0系统,基本上都都是基于7.0以上系统,基本上都不能够获得ROOT的su权限, ...

  9. MySQL基础知识-安装MySQL

    前导: 昨天去参加了一个面试,公司不太大,是一家日资企业,在国内有几家分公司,面试官问到了MySQL的基本操作和性能优化,说了一大堆,倒是比较轻松的过了,但是面试结束之后,想了一下,基本操作忘的还是挺 ...

  10. Windows7安装 docker-compose的过程

    Docker在Windows7系统上安装成功后[详情见Windows7下docker的安装以及遇到的问题],要用到docker-compose相关命令,而docker-compose相关命令在dock ...