UVA11383 Golden Tiger Claw —— KM算法
题目链接:https://vjudge.net/problem/UVA-11383


题解:
根据KM()算法,标杆满足:l(x) + l(y) >= w(x, y) 。
当求完最大权匹配之后,所有标杆在满足:l(x) + l(y) >= w(x, y) 的条件下,和最小。
代码如下:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int INF = 2e9;
const LL LNF = 9e18;
const int mod = 1e9+;
const int MAXN = +; int nx, ny;
int g[MAXN][MAXN], linker[MAXN], lx[MAXN], ly[MAXN], slack[MAXN];
bool visx[MAXN], visy[MAXN]; bool DFS(int x)
{
visx[x] = true;
for(int y = ; y<=ny; y++)
{
if(visy[y]) continue;
int tmp = lx[x] + ly[y] - g[x][y];
if(tmp==)
{
visy[y] = true;
if(linker[y]==- || DFS(linker[y]))
{
linker[y] = x;
return true;
}
}
else
slack[y] = min(slack[y], tmp);
}
return false;
} void KM()
{
memset(linker, -, sizeof(linker));
memset(ly, , sizeof(ly));
for(int i = ; i<=nx; i++)
{
lx[i] = -INF;
for(int j = ; j<=ny; j++)
lx[i] = max(lx[i], g[i][j]);
} for(int x = ; x<=nx; x++)
{
for(int i = ; i<=ny; i++)
slack[i] = INF;
while(true)
{
memset(visx, , sizeof(visx));
memset(visy, , sizeof(visy)); if(DFS(x)) break;
int d = INF;
for(int i = ; i<=ny; i++)
if(!visy[i])
d = min(d, slack[i]); for(int i = ; i<=nx; i++)
if(visx[i])
lx[i] -= d;
for(int i = ; i<=ny; i++)
{
if(visy[i]) ly[i] += d;
else slack[i] -= d;
}
}
}
} int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
nx = ny = n;
for(int i = ; i<=nx; i++)
for(int j = ; j<=ny; j++)
scanf("%d",&g[i][j]); KM();
int sum = ;
for(int i = ; i<=nx; i++) printf("%d ", lx[i]), sum += lx[i];
printf("\n");
for(int i = ; i<=ny; i++) printf("%d ", ly[i]), sum += ly[i];
printf("\n");
printf("%d\n", sum);
}
}
UVA11383 Golden Tiger Claw —— KM算法的更多相关文章
- UVA11383 Golden Tiger Claw KM算法
题目链接:传送门 分析 这道题乍看上去没有思路,但是我们仔细一想就会发现这道题其实是一个二分图最大匹配的板子 我们可以把这道题想象成将男生和女生之间两两配对,使他们的好感度最大 我们把矩阵中的元素\( ...
- uva11383 Golden Tiger Claw 深入理解km算法
/** 题目: uva11383 Golden Tiger Claw 深入理解km算法 链接:https://vjudge.net/problem/UVA-11383 题意:lv 思路:lrj训练指南 ...
- UVA11383 Golden Tiger Claw
题目 UVA11383 Golden Tiger Claw 做法 \(KM\)好题啊,满足所有边\(l(x)+l(y)≥w(x,y)\)(个人理解,如不对请及时留言),这样能满足\(\sum\limi ...
- UVA-11383 Golden Tiger Claw (KM算法)
题目大意:一张可行二分图的权值以邻接矩阵的形式给了出来,现在要找每一个节点的可行顶标,使顶标和最小. 题目分析:直接用KM算法,结束后顶标之和最小...模板题. 代码如下: # include< ...
- 【UVA 11383】 Golden Tiger Claw (KM算法副产物)
Omi, Raymondo, Clay and Kimiko are on new adventure- in search of new Shen Gong Wu. But EvilBoy Geni ...
- UVA 11383 - Golden Tiger Claw(二分图完美匹配扩展)
UVA 11383 - Golden Tiger Claw 题目链接 题意:给定每列和每行的和,给定一个矩阵,要求每一个格子(x, y)的值小于row(i) + col(j),求一种方案,而且全部行列 ...
- Golden Tiger Claw(二分图)
Golden Tiger Claw 题意 找到和最小的两个序列a,b满足对于任意i,j有a[i]+b[j]>=c[i][j](矩阵c给出). solution 裸的二分图就水过了-- #incl ...
- UVA 11383 Golden Tiger Claw 金虎爪(KM算法)
题意: 给一个n*n的矩阵,每个格子中有正整数w[i][j],试为每行和每列分别确定一个数字row[i]和col[i],使得任意格子w[i][j]<=row[i]+col[j]恒成立.先输row ...
- 【KM算法】UVA 11383 Golden Tiger Claw
题目大意 给你一个\(n×n\)的矩阵G,每个位置有一个权,求两个一维数组\(row\)和\(col\),使\(row[i] + col[j]\ge G[i][j]\),并且\(∑row+∑col\) ...
随机推荐
- netcore使用AutoMapper
说明:以下是使用过程中看到的其他博主写的,地址如下: 地址一:https://cloud.tencent.com/developer/article/1395155 地址二:https://www.c ...
- MySQL索引与Index Condition Pushdown(二)
实验 先从一个简单的实验开始直观认识ICP的作用. 安装数据库 首先需要安装一个支持ICP的MariaDB或MySQL数据库.我使用的是MariaDB 5.5.34,如果是使用MySQL则需要5.6版 ...
- 虚拟机(Visual Machine)的云平台的自动伸缩扩容(auto-scaling)技术
云计算平台中允许客户依据应用的负载进行云计算资源的弹性动态伸缩(理想的情况是实现一个用多少付费多少的模型,最大限度地降低用户的运营成本) 在进行讨论之前,先对几个名词进行定义 1)客户:使用云服务的人 ...
- Session保存用户名到Session域对象中
Session保存用户名 1.构造登录界面 用户名: 密 码: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 <!DOCTYPE html> < ...
- js82:CSS的Style,image的重定位,getElementById,getElementsByTagName,location.href
原文发布时间为:2008-11-10 -- 来源于本人的百度文章 [由搬家工具导入] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Tran ...
- 线程&线程池
线程 进程和线程: 进程只是用来把资源集中到一起(进程只是一个资源单位,或者说资源集合),而线程才是cpu上的执行单位. 注意:两个都是过程 线程一个特点: 一个进程中,多个线程共享资源 线程和进程区 ...
- socket相关
socket层 图示,没有找到socket,那么socket层在哪儿呢? 看图: socket是什么 Socket是应用层与TCP/IP协议族通信的中间软件抽象层,它是一组接口.在设计模式中,Sock ...
- SQL SERVER 2012 第三章 使用INSERT语句添加数据
INSERT [TOP (<expression>) [PERCENT] [INTO] <tabular object>[(column list)][OUTPUT <o ...
- Java实现网页截屏
原文:http://www.open-open.com/code/view/1424006089452 import java.awt.AWTException; import java.awt.De ...
- IPTABLES基本例子
iptables –F #删除已经存在的规则 iptables -P INPUT DROP #配置默认的拒绝规则.基本规则是:先拒绝所有的服务,然后根据需要再添加新的规则. iptables -A I ...