二分图的最小顶点覆盖:用最少的点,让每条边都至少和其中一个点关联。
     最大匹配数 = 最小点覆盖数(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(最小点覆盖)的更多相关文章

  1. poj 1325 Machine Schedule 最小点覆盖

    题目链接:http://poj.org/problem?id=1325 As we all know, machine scheduling is a very classical problem i ...

  2. HDU1150 Machine Schedule(二分图最大匹配、最小点覆盖)

    As we all know, machine scheduling is a very classical problem in computer science and has been stud ...

  3. hdu 1150 Machine Schedule 最少点覆盖转化为最大匹配

    Machine Schedule Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...

  4. hdu 1150 Machine Schedule 最少点覆盖

    Machine Schedule Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...

  5. hdu 1150 Machine Schedule(最小顶点覆盖)

    pid=1150">Machine Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/327 ...

  6. hdu1150 Machine Schedule 经典二分匹配题目

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1150 很经典的二分题目 就是求最小点覆盖集 二分图最小点覆盖集=最大匹配数 代码: #include& ...

  7. HDU1150 Machine Schedule

    匈牙利算法 目前为止还是半懂不懂的状态 #include<iostream> #include<cstdio> #include<cstring> using na ...

  8. 【hdu1150】【Machine Schedule】二分图最小点覆盖+简单感性证明

    (上不了p站我要死了,侵权度娘背锅) 题目大意 有两台机器A和B以及N个需要运行的任务.每台机器有M种不同的模式,而每个任务都恰好在一台机器上运行.如果它在机器A上运行,则机器A需要设置为模式ai,如 ...

  9. [poj1325] Machine Schedule (二分图最小点覆盖)

    传送门 Description As we all know, machine scheduling is a very classical problem in computer science a ...

  10. HDU - 1150 POJ - 1325 Machine Schedule 匈牙利算法(最小点覆盖)

    Machine Schedule As we all know, machine scheduling is a very classical problem in computer science ...

随机推荐

  1. linux mysql数据库安装(tar.gz)

    概述 mysql数据库在linux下可以充分发挥威力,mysql数据库越来越受到软件公司的青睐,为什么呢? 免费.跨平台.轻.支持多并发 在北京很多软件公司属于创业型的中.小公司,从节约成本的角度考虑 ...

  2. 【BZOJ 1069】 凸包+旋转卡壳

    1069: [SCOI2007]最大土地面积 Description 在某块平面土地上有N个点,你可以选择其中的任意四个点,将这片土地围起来,当然,你希望这四个点围成的多边形面积最大. Input 第 ...

  3. Java Web开发 之小张老师总结GET和POST区别

    get和post区别1.传输方式不同,get在request-line中传输(即在URL中传输).post在request-line及 request-body中传输(可认为隐藏传输)2.get传输长 ...

  4. Android隐藏输入法键盘(hideSoftInputFromInputMethod没有效果)

    在个别时候,需要强制隐藏Android输入法键盘,如当前键盘正在显示,这个时候点击了侧滑面板,就要强制隐藏输入法键盘.网上常见的方法有: 1. InputMethodManager imm = (In ...

  5. Hadoop常用命令汇总

    启动Hadoop 进入HADOOP_HOME目录. 执行sh bin/start-all.sh 关闭Hadoop 进入HADOOP_HOME目录. 执行sh bin/stop-all.sh 1.查看指 ...

  6. ScrollView can host only one direct child 解决

    主要是ScrollView内部只能有一个子元素,即不能并列两个子元素,所以需要把所有的子元素放到一个LinearLayout内部或RelativeLayout等其他布局方式让后再在这个layout外部 ...

  7. Civil3D二次开发 启动Civil3D异常

    用Com方式启动Civil3D时,经常会在第一次启动时出现各种异常. 1. RPC_E_CALL_REJECTED 0x80010001 被呼叫方拒绝接收呼叫 解决方案:外部程序通过COM启动Auto ...

  8. Convert boolean values to strings 'Yes' or 'No'.

    Convert boolean values to strings 'Yes' or 'No'. Complete the bool_to_word (Javascript: boolToWord ) ...

  9. POJ 1269 (直线相交) Intersecting Lines

    水题,以前总结的模板还是很好用的. #include <cstdio> #include <cmath> using namespace std; ; int dcmp(dou ...

  10. HNOI2008明明的烦恼

    写的很好的题解:http://www.cnblogs.com/zhj5chengfeng/archive/2013/08/23/3278557.html 我这种蒻蒻什么都不会啊…… 代码:(copy的 ...