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.
题解:有两个机器A,B和N个要执行的任务。每个机器有M中不同的模式,每个任务恰好在一个机器上执行。如果在A机器上执行,A机器模式应为Ai,在B机器上执行,则B机器的模式为Bi,任务顺序任意,但是每次切换模式机器要关一次机,安排合理的方案使得机器重启次数最少。
题意转了半天。。这是个最小点覆盖的问题。当然知道了这是什么问题那么解起来就方便了。
二分图最小点覆盖=最大匹配数。
#include<cstdlib>
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#define LL long long
#define maxn 1001
#define INF 2147483646
using namespace std;
int vit[maxn];
int map[maxn][maxn];
int link[maxn];
int n,m,k;
bool dfs(int u)
{
for(int i=0;i<m;i++)
{
if(!vit[i]&&map[u][i])
{
vit[i]=1;
if(link[i]==-1||dfs(link[i]))//反向找出增广路(交错树)
{
link[i]=u;
return true;
}
}
}
return false;
}
void solve(int &ans)
{
for(int i=0;i<n;i++)
{
memset(vit,0,sizeof(vit));
if(dfs(i))
ans++;
}
}
int main()
{
while(cin>>n,n)
{
int ans=0;
cin>>m>>k;
memset(map,0,sizeof(map));
memset(link,-1,sizeof(link));
for(int i=0;i<k;i++)
{
int t,x,y;
cin>>t>>x>>y;
if(x>0&&y>0)
map[x][y]=1;
}
solve(ans);
cout<<ans<<endl;
}
}