二分图的最小顶点覆盖:用最少的点,让每条边都至少和其中一个点关联。
     最大匹配数 = 最小点覆盖数(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. 漫话C++0x(五)—- thread, mutex, condition_variable

    熟悉C++98的朋友,应该都知道,在C++98中没有thread, mutex, condition_variable这些与concurrency相关的特性支持,如果需要写多线程相关程序,都要借助于不 ...

  2. POJ2349+prim

    最小生成树 /* prim 题意:给定一些点,一些卫星,一个卫星能连接两个点,点和点之间通信有一定的距离限制. 问能使得所有的点联通的最小距离. */ #include<stdio.h> ...

  3. HDU4611+数学

    /* 找规律 题意:abs(i%A - i%B) 对i从0~N-1求和 从0~N-1一个一个算必TLE,着A,B两者差相同的部分合并起来算 */ #include<stdio.h> #in ...

  4. 【BZOJ 1046】 1046: [HAOI2007]上升序列

    1046: [HAOI2007]上升序列 Description 对于一个给定的S={a1,a2,a3,-,an},若有P={ax1,ax2,ax3,-,axm},满足(x1 < x2 < ...

  5. BZOJ 3533 sdoi 2014 向量集

    设(x,y)为Q的查询点,分类讨论如下:1.y>0:  最大化a*x+b*y,维护一个上凸壳三分即可 2.y<0:最大化a*x+b*y  维护一个下凸壳三分即可 我们考虑对时间建出一棵线段 ...

  6. java:I/O 往原文件追加内容

    原来txt内容: "我要添加内容" import java.io.*; class Test { public static void main(String[] args) { ...

  7. HDFS的命令行操作

    1.namenode –format:格式化DFS 文件系统 2.secondaryNameNode: 运行DFS的 SecondaryNameNode 进程 hadoop secondaryname ...

  8. 使用Mysql命令一次性备份多个数据库(所有数据库)

    通过CMD命令窗口 1.找到Mysql的安装目录\mysql\BIN目录 2. 输入mysqldump --all-databases -h127.0.0.1 -uroot -p123456 > ...

  9. 【HDOJ】2890 Longest Repeated subsequence

    后缀数组的应用.和男人八题那个后缀数组差不多. /* 2890 */ #include <iostream> #include <sstream> #include <s ...

  10. 关于SqlParameter中IN子句查询的问题

    今天调试到方法中代码: String hotelCodes =”’’,’’,’’”; string sqltext ="select * from HotelMedalInfo where ...