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

最基础的二分图最大匹配问题 对于每一个任务把i和j之间连一条边就能够构成一个二分图 那么每一个任务都能够相应一条边 那么如今就是要找最少的点 使这些点能覆盖全部的边 即点覆盖数 又由于二分图的点覆盖数 = 匹配数 那么就是裸的求二分图最大匹配问题了 两边的点数都不超过100直接DFS增广即可了

#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int g[N][N], a[N], b[N], vis[N];
int n, m, k, ans; int dfs(int i) //DFS增广
{
for(int j = 1; j < m; ++j)
{
if(g[i][j] && !vis[j])
{
vis[j] = 1;
if( b[j] == -1 || dfs(b[j]))
{
//机器a的模式i与机器b的模式j匹配
a[i] = j;
b[j] = i;
return 1;
}
}
}
return 0;
} int main()
{
int u, v, t;
while(scanf("%d", &n), n)
{
memset(g, 0, sizeof(g));
scanf("%d%d", &m, &k);
for(int i = 0; i < k; ++i)
{
scanf("%d%d%d", &t, &u, &v);
g[u][v] = 1;
} ans = 0;
memset(a, -1, sizeof(a));
memset(b, -1, sizeof(b));
//状态0不须要重新启动 所以能够忽略0
for(int i = 1; i < n; ++i)
{
if(a[i] == -1) //i没被匹配 以i为起点找一条增广路
{
memset(vis, 0, sizeof(vis));
ans += dfs(i); //
}
} printf("%d\n", ans);
}
return 0;
}
//Last modified : 2015-07-10 14:50

Machine Schedule


Time Limit: 2 Seconds      Memory Limit: 65536 KB


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


ZOJ 1364 Machine Schedule(二分图最大匹配)的更多相关文章

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

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

  2. UVA1194 Machine Schedule[二分图最小点覆盖]

    题意翻译 有两台机器 A,B 分别有 n,m 种模式. 现在有 k 个任务.对于每个任务 i ,给定两个整数$ a_i\(和\) b_i$,表示如果该任务在 A上执行,需要设置模式为 \(a_i\): ...

  3. HDU 1150 Machine Schedule (二分图最小点覆盖)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1150 有两个机器a和b,分别有n个模式和m个模式.下面有k个任务,每个任务需要a的一个模式或者b的一个 ...

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

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

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

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

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

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

  7. poj 2724 Purifying Machine(二分图最大匹配)

    题意: 有2^N块奶酪,编号为00...0到11..1. 有一台机器,有N个开关.每个开关可以置0或置1,或者置*.但是规定N个开关中最多只能有一个开关置*. 一旦打开机器的开关,机器将根据N个开关的 ...

  8. (step6.3.3)hdu 1150(Machine Schedule——二分图的最小点覆盖数)

    题目大意:第一行输入3个整数n,m,k.分别表示女生数(A机器数),男生数(B机器数),以及它们之间可能的组合(任务数). 在接下来的k行中,每行有3个整数c,a,b.表示任务c可以有机器A的a状态或 ...

  9. POJ - 1325 Machine Schedule 二分图 最小点覆盖

    题目大意:有两个机器,A机器有n种工作模式,B机器有m种工作模式,刚開始两个机器都是0模式.假设要切换模式的话,机器就必须的重新启动 有k个任务,每一个任务都能够交给A机器的i模式或者B机器的j模式完 ...

随机推荐

  1. [BZOJ 4033] 树上染色

    Link: BZOJ 4033 传送门 Solution: 此题用到了计算贡献的方法, 将 多条路径的路径和  $->$ $\sum_{i=1}^{n-1} w[i]*cnt[i]$ 这样我们由 ...

  2. 【Trie】bzoj1212 [HNOI2004]L语言

    枚举每个文章里已经在Trie中被标记为可能是分割处的字符,然后再从此处跑Trie,继续向后标记.由于单词数很少,因此复杂度可以接受,O(n*m*Len). #include<cstdio> ...

  3. python3开发进阶-Django框架中的ORM的常用(增,删,改,查)操作

    阅读目录 如何在Django终端打印SQL语句 如何在Python脚本中调用Django环境 操作方法 单表查询之神奇的下划线 ForeignKey操作 ManyToManyField 聚合查询和分组 ...

  4. STL之vector2

    描述 依次输入n个整数,每次输入时检查该值是否已经出现在vector中,如果存在则不插入,否则将其插入到开头位置. 部分代码已经给出,请补充完整,提交时请勿包含已经给出的代码. int main() ...

  5. 可见性-volatile

    出处: http://blog.csdn.net/vking_wang/article/details/9982709

  6. Java使用POM一JAR包的形式管理JavaScript文件-WebJars

    说明:原来JS框架还可以使用POM进行管理的.WebJars是一个很神奇的东西,可以让大家以JAR包的形式来使用前端的各种框架.组件. 什么是WebJars 什么是WebJars?WebJars是将客 ...

  7. ZooKeeper本身是一个分布式应用程序,为写入分布式应用程序提供服务。

    ZooKeeper本身是一个分布式应用程序,为写入分布式应用程序提供服务. 作为ZooKeeper架构的一部分的每个组件在下表中进行了说明. 部分 描述 Client(客户端) 客户端,我们的分布式应 ...

  8. Apache -Common-lang包使用

    原文:http://weigang-gao.iteye.com/blog/2188739 ArrayUtils – 用于对数组的操作,如添加.查找.删除.子数组.倒序.元素类型转换等: BitFiel ...

  9. Redis编程实践【pub/sub】

    原文:http://shift-alt-ctrl.iteye.com/blog/1867454 Redis或许已经在很多企业开始推广并试水,本文也根据个人的实践,简单描述一下Redis在实际开发过程中 ...

  10. 疑似checkpoint堵塞数据库连接

    注:这个说法是不成立的,问题已经解决,但是无法正确的定位到具体什么原因:[20140702]奇怪的应用程序超时 背景: 开发通过应用程序的日志发现间歇性的出现,数据库连接超时 原因: 只能大概猜测,没 ...