个人心得:二分图啥的一点都不知道,上网借鉴了下,请参考http://blog.csdn.net/thundermrbird/article/details/52231639

加上自己的了解,二分图就是将图形拆分成俩半,俩边的点通过边界相连接。匹配就是不存在俩条边存在同一顶点,就是一个顶点最多连接一条边。

匈牙利算法就是用增广路进行更新,仔细一想确实如此,如果存在这样的途径那么必然可以用亦或就行维护更新,细节看参考。

不过碍于自己图论太low,还是无法运用的好,比如这题,就是最小覆盖点,关于最小覆盖点等于最大匹配数还没搞明白。

总的来说这就是给我提供一个二分最大匹配的模板吧,算法细节方面有时间还是要去学的,不能单纯为了做题而学习算法!

励志语:没什么能够打倒你,能打倒你的只有你的自卑和懦弱。前方大路终究变得宽阔,加油。

题目:

As we all know, machine scheduling is a very classical problem in computer science and has been studied for a very long history. Scheduling problems differ widely in the nature of the constraints that must be satisfied and the type of schedule desired. Here we consider a 2-machine scheduling problem.

There are two machines A and B. Machine A has n kinds of working modes, which is called mode_0, mode_1, ..., mode_n-1, likewise machine B has m kinds of working modes, mode_0, mode_1, ... , mode_m-1. At the beginning they are both work at mode_0.

For k jobs given, each of them can be processed in either one of the two machines in particular mode. For example, job 0 can either be processed in machine A at mode_3 or in machine B at mode_4, job 1 can either be processed in machine A at mode_2 or in machine B at mode_4, and so on. Thus, for job i, the constraint can be represent as a triple (i, x, y), which means it can be processed either in machine A at mode_x, or in machine B at mode_y.

Obviously, to accomplish all the jobs, we need to change the machine's working mode from time to time, but unfortunately, the machine's working mode can only be changed by restarting it manually. By changing the sequence of the jobs and assigning each job to a suitable machine, please write a program to minimize the times of restarting machines.

Input

The input file for this program consists of several configurations. The first line of one configuration contains three positive integers: n, m (n, m < 100) and k (k < 1000). The following k lines give the constrains of the k jobs, each line is a triple: i, x, y.

The input will be terminated by a line containing a single zero.

Output

The output should be one integer per line, which means the minimal times of restarting machine.

Sample Input

5 5 10
0 1 1
1 1 2
2 1 3
3 1 4
4 2 1
5 2 2
6 2 3
7 2 4
8 3 3
9 4 3
0

Sample Output

3
 #include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<string>
#include<algorithm>
using namespace std;
const int inf=0x3f3f3f3f;
const int maxa=;
int g[maxa][maxa];
int book[maxa];
int link[maxa];
int n,m,k;
int dfs(int u){
int v;
for(v=;v<m;v++)
if(g[u][v]&&!book[v])
{
book[v]=;
if(link[v]==-||dfs(link[v]))
{
link[v]=u;
return ;
}
}
return ;
}
int hungary()
{
int res=;
int u;
memset(link,-,sizeof(link));
for(int i=;i<n;i++)
{
memset(book,,sizeof(book));
if(dfs(i)) res++;
}
return res;
}
int main(){
while(cin>>n){
if(n==) break;
memset(g,,sizeof(g));
cin>>m>>k;
int x,y,z;
while(k--){
cin>>x>>y>>z;
if(y>&&z>) g[y][z]=;
}
cout<<hungary()<<endl; } return ;
}
												

Machine Schedule(二分图匹配之最小覆盖点,匈牙利算法)的更多相关文章

  1. hdu - 1150 Machine Schedule (二分图匹配最小点覆盖)

    http://acm.hdu.edu.cn/showproblem.php?pid=1150 有两种机器,A机器有n种模式,B机器有m种模式,现在有k个任务需要执行,没切换一个任务机器就需要重启一次, ...

  2. POJ-1325 Machine Schedule 二分图匹配 最小点覆盖问题

    POJ-1325 题意: 有两台机器A,B,分别有n,m种模式,初始都在0模式,现在有k项任务,每项任务要求A或者B调到对应的模式才能完成.问最少要给机器A,B调多少次模式可以完成任务. 思路: 相当 ...

  3. HDU 1150 Machine Schedule (最小覆盖,匈牙利算法)

    题意: 有两台不同机器A和B,他们分别拥有各种运行模式1~n和1~m.现有一些job,需要在某模式下才能完成,job1在A和B上需要的工作模式又可能会不一样.两台机器一开始处于0模式,可以切换模式,但 ...

  4. ZOJ 1364 Machine Schedule(二分图最大匹配)

    题意 机器调度问题 有两个机器A,B A有n种工作模式0...n-1 B有m种工作模式0...m-1 然后又k个任务要做 每一个任务能够用A机器的模式i或b机器的模式j来完毕 机器開始都处于模式0 每 ...

  5. poj 1325 Machine Schedule 二分匹配,可以用最大流来做

    题目大意:机器调度问题,同一个任务可以在A,B两台不同的机器上以不同的模式完成.机器的初始模式是mode_0,但从任何模式改变成另一个模式需要重启机器.求完成所有工作所需最少重启次数. ======= ...

  6. hdu 1150 Machine Schedule (二分匹配)

    Machine Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  7. UVA 1663 Purifying Machine (二分图匹配,最大流)

    题意: 给m个长度为n的模板串,模板串由0和1和*三种组成,且每串至多1个*,代表可0可1.模板串至多匹配2个串,即*号改成0和1,如果没有*号则只能匹配自己.问:模板串可以缩减为几个,同样可以匹配原 ...

  8. hdu 4185 Oil Skimming(二分图匹配 经典建图+匈牙利模板)

    Problem Description Thanks to a certain "green" resources company, there is a new profitab ...

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

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

随机推荐

  1. canvas drawimage绘制图像出错(默认canvas300*150)解决办法

    今天在开发中,再一次踩了以前踩过的坑,写完程序在这里写一下,分享给大家也避免再次遇坑. //默认的canvas <canvas id ="canvas"></ca ...

  2. springboot获取配置文件中的内容

    代码: GrilApplication.java @SpringBootApplication public class GrilApplication { public static void ma ...

  3. js数组与字符串的相互转换

    一.数组转字符串 需要将数组元素用某个字符连接成字符串,示例代码如下: var a, b,c; a = new Array(a,b,c,d,e); b = a.join('-'); //a-b-c-d ...

  4. LR----实现WebService测试

    测试WebService时,需要导入WSDL:同SoapUI WSDL:http://ws.webxml.com.cn/webservices/DomesticAirline.asmx?wsdl 场景 ...

  5. Codeforces Round #423

    这一次又崩了,最后只a了一题(还是被hack后才发现的错误) 第一题水题,多用一个数保存2-1后的数,注意先用2的桌子,再用这个 #include<map> #include<set ...

  6. HDU-4705-树形dp/组合数学

    Y Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submiss ...

  7. 原生javascript-Tab选项卡-面向对象

    分析个人用原生JS获取类名元素的代码: getByClassName:function(className,parent){ var elem = [], node = parent != undef ...

  8. H3C Huawei 交换机 IPv6环境配置

    # 使能IPv6报文转发功能. <Sysname> system-view [Sysname] ipv6 # 使能DHCPv6服务器功能. <Sysname> system-v ...

  9. bzoj2700

    题解: dp dp[i][j]表示i个红,j个绿的最小代价 然后再加上两位k,l,表示k个红连,l个绿连 然后转移 代码: #include<bits/stdc++.h> using na ...

  10. 集成xadmin源码到项目的正式姿势

    xadmin是强大的,但是为了更好的后期定制开发,可能会修改到xadmin的源码. 因此还是推荐将xadmin源码集成到自己的项目中. 1.pip install xadmin 安装xadmin的模块 ...