POJ 1325 Machine Schedule (最大二分匹配)
来源:互联网 发布:淘宝开店类目怎么写 编辑:程序博客网 时间:2024/05/20 22:06
Machine Schedule
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 9868 Accepted: 4193
Description
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.
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.
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 100 1 11 1 22 1 33 1 44 2 15 2 26 2 37 2 48 3 39 4 30
Sample Output
3
Source
Beijing 2002
#include <cstdio>#include <cstring>#include <vector>using namespace std;const int maxn=111;vector<int>edge[maxn];bool vis[maxn];int mach[maxn],n,m;bool find(int now){ int i,v; for(i=0; i<edge[now].size(); ++i) if(!vis[v=edge[now][i]]) { vis[v]=true; if(mach[v]==-1||find(mach[v])) { mach[v]=now; return true; } } return false;}int main(){ int k,i,id,x,y; while(scanf("%d",&n)&&n) { scanf("%d%d",&m,&k); memset(mach,-1,sizeof(mach)); for(i=0; i<n; i++) edge[i].clear(); for(i=0; i<k; i++) { scanf("%d%d%d",&id,&x,&y); if(x&&y) edge[x].push_back(y); } int ans=0; for(i=1; i<n; i++) { memset(vis,0,sizeof(vis)); if(find(i)) ans++; } printf("%d\n",ans); } return 0;}
- POJ 1325 Machine Schedule (最大二分匹配)
- poj - 1325 - Machine Schedule(二分图最大匹配)
- poj 1325 Machine Schedule 二分匹配,可以用最大流来做
- 【二分图|最大匹配】POJ-1325 Machine Schedule
- poj 1325 Machine Schedule 二分匹配
- Machine Schedule - POJ 1325 二分图匹配
- POJ 1325 Machine Schedule(二分图匹配)
- POJ 1325Machine Schedule(二分图最大匹配最小点覆盖)
- POJ 1325-Machine Schedule(二分图_最大匹配最小点覆盖)
- POJ 1325 Machine Schedule (最小点覆盖 && 二分图最大匹配)
- 求解二分图的最大匹配的匈牙利算法---POJ 1325 Machine Schedule
- POJ1325 Machine Schedule 二分图最大匹配
- poj 1325 Machine Schedule 匈牙利二分匹配 基础
- hdu 1150 || poj 1325 Machine Schedule (二分图匹配)
- POJ-1325 && HDU-1150 Machine Schedule 二分图匹配
- POJ 1325 Machine Schedule(二分匹配 最小点覆盖)
- 【图论】【二分图匹配】[POJ 1325]Machine Schedule
- poj 1325 Machine Schedule 二分图匹配+DFS实现
- 我的博客转到CSDN了
- 划分树
- VS2010 CString转为char的方法
- ubuntu11.04软件源更新
- c#中和并个excel表格的方法
- POJ 1325 Machine Schedule (最大二分匹配)
- AndroidManifest.xml文件详解(service)
- ByteBuffer的allocate和allocateDirect
- 回滚已删除的数据库表数据
- 开发CXF JAVA客户端
- [Ruby学习总结]Ruby中的方法
- 国内芯片代理商
- 多平台代码对比示例——LEADTOOLS OCR .NET平台(一)
- 九度OJ 题目1477:怪异的洗牌