hdu1150-Machine Schedule(最小点覆盖)
二分图的最小顶点覆盖:用最少的点,让每条边都至少和其中一个点关联。
最大匹配数 = 最小点覆盖数(Konig 定理)
水题……
突然发现我以前的匈牙利算法模版有问题……因为这里左边的点时1~n,右边的点是1~m,所以有不同的点标号是相同的,注意注意!
因为这个算法本身是O(n^2)的,所以数据必然不会很大,放心用邻接矩阵存吧……
如果某个边有0,那么不需要加进来,每个产品应该只会出现一次,不然就不对了吧……我想了好久,因为题目并没有说每个产品只出现一次……
//hdu1150
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const int N = ;
int n, m, k;
bool mp[N][N]; int match[N];
bool used[N]; bool find(int u) {
for (int v = ; v < m; ++v) {
if (mp[u][v] && !used[v]) {
used[v] = true;
if (match[v] == - || find(match[v])) {
match[v] = u;
return true;
}
}
}
return false;
} int hungary() {
memset(match, -, sizeof match);
int ans = ;
for (int i = ; i < n; ++i) {
memset(used, false, sizeof used);
if (find(i)) ++ans;
}
return ans;
} int main() {
//freopen("in", "r", stdin);
while (~scanf("%d", &n) && n) {
scanf("%d%d", &m, &k);
int u, v;
memset(mp, false, sizeof mp);
while (k--) {
scanf("%*d%d%d", &u, &v);
if (!u || !v) continue;
mp[u][v] = true;
}
printf("%d\n", hungary());
}
return ;
}
hdu1150-Machine Schedule(最小点覆盖)的更多相关文章
- poj 1325 Machine Schedule 最小点覆盖
题目链接:http://poj.org/problem?id=1325 As we all know, machine scheduling is a very classical problem i ...
- HDU1150 Machine Schedule(二分图最大匹配、最小点覆盖)
As we all know, machine scheduling is a very classical problem in computer science and has been stud ...
- hdu 1150 Machine Schedule 最少点覆盖转化为最大匹配
Machine Schedule Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...
- hdu 1150 Machine Schedule 最少点覆盖
Machine Schedule Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...
- hdu 1150 Machine Schedule(最小顶点覆盖)
pid=1150">Machine Schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/327 ...
- hdu1150 Machine Schedule 经典二分匹配题目
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1150 很经典的二分题目 就是求最小点覆盖集 二分图最小点覆盖集=最大匹配数 代码: #include& ...
- HDU1150 Machine Schedule
匈牙利算法 目前为止还是半懂不懂的状态 #include<iostream> #include<cstdio> #include<cstring> using na ...
- 【hdu1150】【Machine Schedule】二分图最小点覆盖+简单感性证明
(上不了p站我要死了,侵权度娘背锅) 题目大意 有两台机器A和B以及N个需要运行的任务.每台机器有M种不同的模式,而每个任务都恰好在一台机器上运行.如果它在机器A上运行,则机器A需要设置为模式ai,如 ...
- [poj1325] Machine Schedule (二分图最小点覆盖)
传送门 Description As we all know, machine scheduling is a very classical problem in computer science a ...
- HDU - 1150 POJ - 1325 Machine Schedule 匈牙利算法(最小点覆盖)
Machine Schedule As we all know, machine scheduling is a very classical problem in computer science ...
随机推荐
- ECNU-2574 Principles of Compiler
题意: 给出编译规则,求是否满足条件 A:= '(' B')'|'x'. B:=AC. C:={'+'A}. 其中{}表示里面的内容可以出现0次或者多次 注意点见代码注释 #include ...
- SpringMVC ResponseBody返回中文乱码解决方案
@RequestMapping(value = "/getForm") @ResponseBody public List<String> getForm(String ...
- php简单文件上传类
<?php header("Content-Type:text/html; charset=utf-8"); if($_POST['submit']){ $upfiles = ...
- nginx做负载均衡配置文件
nginx做负载均衡是在反向代理的基础上做的,代码如下: ## Basic reverse proxy server ## ## Apache backend for www.baidu.com ## ...
- 1400 - "Ray, Pass me the dishes!"
哈哈,原来题意看错了,但有多个解的时候,输出起点靠前的,如果起点一样,则输出终点靠前的,修改后AC的代码如下: #include <cstdio> #include <iostrea ...
- JavaScript DOM高级程序设计 2.4-try{}catch{}--我要坚持到底!
先看一段有异常的语句 var sound = 'Roar!'; function myOrneryBeast() { this.style.color='green';//window没有style属 ...
- bzoj1057,poj3250
bzoj1057本质上是求最大子矩阵: 第一问是一个经典的O(n2)dp 第二问就是最大子矩阵,回眸一下当年卡了我很久的问题: 首先穷举显然不行(这不废话吗?): 首先我们预处理每个点可以最大向上延展 ...
- Archlinux里面安装VMware Tools
用虚拟机学习linux确实很方便,但是和主机的文件共享是个大问题,VMWARE TOOLS可以很好的解决这个问题,但是在ARCH里却不能向大多数linux那样方便的安装,在查了很多帖子试了无数遍之后, ...
- TPL
namespace TPLTest { public partial class Form1 : Form { public Form1() { InitializeComponent(); } pr ...
- UESTC 250 windy数(数位DP)
题意:题意:求区间[A,B]之间的,不含前导0,且相邻两数位之间相差至少为2的正整数有多少个. 分析:dp[i][j]表示,长度为i.以j为结尾的表示的个数,再加一个前导0判断即可 #include ...