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 ...
随机推荐
- 修改jmeter jvm参数
记录下常用的linux下 jmeter jvm参数修改,打开jmeter安装目录/bin/jmeter(非jmeter.sh) 1. 修改默认堆内存大小 #默认的 HEAP="-Xms512 ...
- like 大数据字段 查询慢
对于ntext的字段,作为查询条件的时候速度会很慢,比如以下语句: select * from T_KNOWLEDGE where CONTENTS like '%Oracle TimesTen In ...
- ios loading视图动画(模仿58同城)
最近看了58同城的加载视图,感觉很不错,如下图: 所以想模仿写一个,下载58同城的app,解压,发现它用的是图片来实现的动画效果, 并不是绘制出来的,所以这就相对简单些了,其实整个动画的逻辑不复杂,无 ...
- MySQL相关知识
字符串拼接 select * from tablename where mydata like CONCAT(CURDATE(), '%') limit 3 这里concat是字符串拼接, conca ...
- python string 连接test
def strTest(): name = "" for i in range(10): name += "hello" #print name def str ...
- 新建一个struts2项目
1,新建-动态web项目: 2,将struts2的必要jar包复制到WEB-INF\lib文件夹下,一共有9个,如图一所示. 图一 3,配置web.xml文件,将以下内容写到web.xml文件中. & ...
- android下升级软件介绍
编译android: 生成:system.img,ramdisk.img,userdata.img映像文件. ramdisk.img是emulator的文件系统 system.img包括了主要的包.库 ...
- HTML5学习(八)----Web存储
参考地址:http://www.w3school.com.cn/html5/html_5_webstorage.asp 在客户端存储数据 HTML5 提供了两种在客户端存储数据的新方法: localS ...
- ubuntu程序安装方法
以前一直使用window,今天安装了一个ubuntu系统(如果有同学也想装,建议装英文版的),因为以前ubuntu系统用的不多,所以安装软件就是一个问题. 就以安装chrome来说吧: 1.在Goog ...
- Innodb 锁系列2 事务锁
上一篇介绍了Innodb的同步机制锁:Innodb锁系列1 这一篇介绍一下Innodb的事务锁,只所以称为事务锁,是因为Innodb为实现事务的ACID特性,而添加的表锁或者行级锁. 这一部分分两篇来 ...