题意 机器调度问题 有两个机器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


最新文章

  1. Mysql主从配置,实现读写分离
  2. 【BZOJ 4518】【SDOI 2016 Round1 Day2 T3】征途
  3. myeclipse 第一个web project
  4. Spring面试问题
  5. Akka(一) - akka的wordcount
  6. Android中显示网页的多种方式
  7. 1048: [HAOI2007]分割矩阵 - BZOJ
  8. Unity3D中的工具类
  9. CSDN-Markdown语法集锦
  10. 关于BOM 的详细介绍
  11. HTML页面内容禁止选择、复制、右键
  12. ruby安装sass报错解决办法
  13. windows下用pip安装软件超时解决方案
  14. 把一个机器上1天内新增的文件用rsync传送到另外一台机器
  15. nodejs-5.2 axios请求
  16. Gym 100963B
  17. IntelJ idea下lombok 不生效的问题(@Builder等注解不生效的问题)解决,lombok Plugin插件安装
  18. Python的命令模式和交互模式
  19. uml 图学习记录
  20. Sereja and Two Sequences CodeForces - 425C (dp)

热门文章

  1. 【树上莫队】【带修莫队】bzoj3052 [wc2013]糖果公园
  2. 【匈牙利算法】BZOJ1059-[ZJOI2007]矩阵游戏
  3. URL 和URI的区别
  4. 使用layer.js注意事项
  5. 网络采集软件核心技术剖析系列(7)---如何使用C#语言搭建程序框架(经典Winform界面,顶部菜单栏,工具栏,左边树形列表,右边多Tab界面)
  6. iOS:Masonry练习详解
  7. 纯C实现面向对象
  8. Tomcat中实现IP访问限制
  9. grpc(3):使用 golang 开发 grpc 服务端和client
  10. Kubernetes用户指南(二)--部署组合型的应用、连接应用到网络中