二分图的最小顶点覆盖:用最少的点,让每条边都至少和其中一个点关联。
     最大匹配数 = 最小点覆盖数(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. html5移动web开发实战必读书记

    原文  http://itindex.net/detail/50689-html5-移动-web 主题 HTML5 一.配置移动开发环境 1.各种仿真器.模拟器的下载安装 http://www.mob ...

  2. 【C++基础】内存操作 getMemory改错

    内存操作的考察点:①指针 ②变量生存期及作用范围 ③动态内存申请和释放 笔试题************************************************************* ...

  3. how to make form:checkboxes in JSP

    retransmitTable.jsp file: <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix=&qu ...

  4. 正确使用STL-MAP中Erase函数

    一切尽在代码中. #include <iostream> #include <map> #include <string> using namespace std ...

  5. HDU4647+贪心

    /* 贪心. 题意:给定一些点 一些边 点和边都有价值.现在A B 选点.求A-B的maxVal 思路:分割边.边的1/2分给两个端点. 如果这两个点被同一个人取,则ok:否则 做减法也行,对题意无影 ...

  6. valgrind基本使用

    1.valgrind是一个内存检测工具,类似的还有purify,insure++等 2.测试文件test.c test.c : main(){ int* a=new int[100]; return ...

  7. [Unity菜鸟] Unity读XML

    1. 在Unity中调试可行,发布成exe可行,发布成web不行 Application.dataPath 在Unity中调试是在“..Assets”文件夹下, 发布成exe文件是在“..yourNa ...

  8. LINQ语句

    http://wenku.baidu.com/link?url=hPKqDWql7DNr6W2MsINakjRYYNXmXywB_U3h9FFMeFjcToYpusI2fYKgHjZSRq7r3ULG ...

  9. node安装插件方法

    node安装插件方法有几种,这里列出常用的两种方法: 方法1: 进入要安装插件的目录,直接用 npm 软件安装包安装,如(安装express): cd /project npm install -g ...

  10. poj3666

    一道不错的dp题 就是最小修改代价,使序列变为一个非下降序或非上升(由于数据较弱直接求非下降即可,当然非上升非下降本质是一样的) 观察可得到,修改后得到的数列中的元素最后一定都在原序列中: 由此我们可 ...