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.

InputThe 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. 
OutputThe 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

大意:两个机器,分别有N个和M个模式,K个工作,每个工作可以用第一个机器的某个模式完成或者用第二个机器的某个模式完成。每次机器切换模式都需要重新启动。
问最少重启几次机器。
这是一个裸的最小点覆盖,还是求一个图中与每条边相邻的最小点集。最大匹配=最小点覆盖
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
using namespace std;
int read(){
int xx=,ff=;char ch=getchar();
while(ch>''||ch<''){if(ch=='-')ff=-;ch=getchar();}
while(ch>=''&&ch<=''){xx=(xx<<)+(xx<<)+ch-'';ch=getchar();}
return xx*ff;
}
const int maxn=;
int lin[maxn],len,N,M,K,ans;
struct edge{
int y,next;
}e[];
inline void insert(int xx,int yy){
e[++len].next=lin[xx];
e[len].y=yy;
lin[xx]=len;
}
int tim,pretim,match[maxn],vis[maxn];
bool hun(int x){
for(int i=lin[x];i;i=e[i].next)
if(vis[e[i].y]<=pretim){
vis[e[i].y]=++tim;
if(match[e[i].y]==||hun(match[e[i].y])){
match[e[i].y]=x;
match[x]=e[i].y;
return ;
}
}
return ;
}
int main(){
//freopen("in","r",stdin);
//freopen("out","w",stdout);
while(){
N=read();
if(!N)
break;
M=read(),K=read();
memset(lin,,sizeof(lin));len=;
for(int i=;i<=K;i++){
read();
int t1=read(),t2=read();
insert(t1,t2+N);
}
ans=;tim=;pretim=;
memset(match,,sizeof(match));
memset(vis,,sizeof(vis));
for(int i=;i<=N+M;i++)
if(!match[i]){
pretim=tim;
vis[i]=++tim;
if(hun(i))
ans++;
}
printf("%d\n",ans);
}
return ;
}
 

最新文章

  1. [转]浅谈CSRF攻击方式
  2. New line
  3. Java 并发工具包 java.util.concurrent 用户指南
  4. 在windows下使用linux命令
  5. Javascript同源策略对context.getImageData的影响
  6. kali 重置 mysql 密码
  7. 【C语言】模拟实现库函数strcat函数
  8. sqlcode、sqlerrm
  9. setf
  10. Delphi下创建异形窗体
  11. [转]Win7、Windows Server 2008下无法在Windows Service中打开一个已经存在的Excel 2007文件问题的解决方案
  12. BeagleBone Black教训四局:简单LED对照实验
  13. Google官方网络框架Volley实战——QQ吉凶测试,南无阿弥陀佛!
  14. [模板] 快速傅里叶变换/FFT/NTT
  15. 【python】实用的logging封装
  16. orangepi one AP模式配置
  17. WebAPI跨域处理
  18. 使用Gitblit 在Windows2008 r2上部署Git Server(完整版)
  19. 基于ARM的模拟器
  20. myeclipse使用小技巧

热门文章

  1. Java_Web三大框架之Hibernate+HQL语言基础
  2. DateTimePicker 控件置空
  3. CAD保存高版本的dwg(com接口)
  4. LOJ 6145 Easy (动态点分治+线段树)
  5. PostgreSQL使用总结
  6. web前端学习总结--HTML
  7. Flask - 模板语言jinja2 和render_template高级用法
  8. Java Web项目实战第1篇之环境搭建
  9. springcloud(三):Eureka服务端
  10. SQLServer中的Cross Apply、Outer Apply