(二分匹配 模板 KM)奔小康赚大钱--hdu--2255
链接:
http://acm.hdu.edu.cn/showproblem.php?pid=2255
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define N 550
#define INF 0x3f3f3f3f int n;
int G[N][N], lx[N], ly[N];//x集合的顶标
int visx[N], visy[N], s[N], used[N];//s是为了找d, visx[i]x中的i有没有被增广过 bool Find(int u)//增广路
{
visx[u] = ;
for(int i=; i<=n; i++)
{
if(!visy[i] && lx[u]+ly[i]==G[u][i])
{
visy[i]=;
if(!used[i] || Find(used[i]))
{
used[i] = u;
return true;
}
}
else
s[i] = min(s[i], lx[u]+ly[i]-G[u][i]);
}
return false;
} int KM()
{
memset(used, , sizeof(used));
memset(lx, , sizeof(lx));
memset(ly, , sizeof(ly)); for(int i=; i<=n; i++)
for(int j=; j<=n; j++)
lx[i] = max(lx[i], G[i][j]); for(int i=; i<=n; i++)
{
for(int j=; j<=n; j++)
s[j] = INF;
while()
{
memset(visx, , sizeof(visx));
memset(visy, , sizeof(visy)); if(Find(i))
break; int d = INF;
for(int j=; j<=n; j++)
if(!visy[j])
d = min(d, s[j]); for(int j=; j<=n; j++)
{
if(visx[j])
lx[j] -= d;
if(visy[j])
ly[j] += d;
}
}
} int res=;
for(int i=; i<=n; i++)
res += G[used[i]][i];
return res;
} int main()
{
while(scanf("%d", &n)!=EOF)
{
int i, j; memset(G, , sizeof(G));
for(i=; i<=n; i++)
for(j=; j<=n; j++)
scanf("%d", &G[i][j]); printf("%d\n", KM());
}
return ;
}
(二分匹配 模板 KM)奔小康赚大钱--hdu--2255的更多相关文章
- 奔小康赚大钱 HDU - 2255(最大权值匹配 KM板题)
奔小康赚大钱 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Subm ...
- 奔小康赚大钱 hdu 2255
奔小康赚大钱 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...
- 奔小康赚大钱 hdu 2255( KM )
http://acm.split.hdu.edu.cn/showproblem.php?pid=2255 带权匹配问题: #include <stdio.h> #include <a ...
- P - 奔小康赚大钱 - hdu 2255(带权值的匹配)
分析:这是一个KM的模板题,也就不多说了,KM最复杂的情况都能过,下面是没有优化过的代码: ****************************************************** ...
- 【HDU 2255】奔小康赚大钱 (最佳二分匹配KM算法)
奔小康赚大钱 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Subm ...
- hdu_2255_奔小康赚大钱(KM带权二分匹配板子)
题目连接:hdu_2255_奔小康赚大钱 存个板子 /* 其实在求最大 最小的时候只要用一个模板就行了, 把边的权值去相反数即可得到另外一个.求结果的时候再去 相反数即可,最大最小有一些地方不同.. ...
- HDU2255 奔小康赚大钱 (最大权完美匹配) 模板题【KM算法】
<题目链接> 奔小康赚大钱 Problem Description 传说在遥远的地方有一个非常富裕的村落,有一天,村长决定进行制度改革:重新分配房子.这可是一件大事,关系到人民的住房问题啊 ...
- HDU 2255 奔小康赚大钱 (KM算法 模板题)
奔小康赚大钱 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Subm ...
- hdu2255 奔小康赚大钱 km算法解决最优匹配(最大权完美匹配)
/** 题目:hdu2255 奔小康赚大钱 km算法 链接:http://acm.hdu.edu.cn/showproblem.php?pid=2255 题意:lv 思路:最优匹配(最大权完美匹配) ...
- HDU2255 奔小康赚大钱 —— 二分图最大权匹配 KM算法
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2255 奔小康赚大钱 Time Limit: 1000/1000 MS (Java/Others) ...
随机推荐
- UEFI BIOS和普通BIOS的区别
作为传统BIOS(Basic Input/Output System)的继任者,UEFI拥有前辈所不具备的诸多功能,比如图形化界面.多种多样的操作方式.允许植入硬件驱动等等.这些特性让UEFI相比于传 ...
- 迷你MVVM框架 avalonjs 学习教程18、一步步做一个todoMVC
大凡出名的MVC,MVVM框架都有todo例子,我们也搞一下看看avalon是否这么便宜. 我们先从react的todo例子中扒一下HTML与CSS用用. <!doctype html> ...
- Mac和iOS开发资源汇总—更新于2013-10-14
小引本文主要汇集一些苹果开发的资源,会经常更新,建议大家把这篇文章单独收藏(在浏览器中按command+D).今天(2013年10月14日)收录了answer哥(黄爱武)的博客,欢迎大家围观! 今天( ...
- Linux初学时的一些常用命令(2)
文件的操作 创建一个文件 touch 文件名 创建一个空白的文件 复制文件 cp 文件 目录/文件名 例如: cp 1.txt 2.txt cp 1.tx ...
- js 获取input选择的图片的信息
1JS $("#btn").click(function () { var imageEle = document.getElementById("images" ...
- go 第一个项目
官方下载go: https://golang.org/dl/ 安装完成后:cmd命令下:go go env:查看当前的环境配置:
- Rabbitmq 基本属性
MQ全称为Message Queue, 是一种分布式应用程序的的通信方法,它是消费-生产者模型的一个典型的代表,producer往消息队列中不断写入消息,而另一端consumer则可以读取或者订阅队列 ...
- exception keynote
[exception keynote] Note that the parentheses around this tuple are required, because except ValueEr ...
- android mapView
1.Because the Maps library is not a part of the standard Android library, you must declare it in the ...
- ECMAScript6新特性之Array API
一 填充数组 var arr = new Array(5); arr.fill('abc',2,4); console.log('Array.prototype.fill',arr); // [und ...