Problem 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. 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. 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 |
#include <iostream>
#include <string.h>
using namespace std;
int n,m,k;
int we[105][105];
bool vis[105];
int pre[105];
bool dfs(int s){
for(int i=0;i<m;i++){
if(we[s][i] && !vis[i]){
vis[i]=1;
if(pre[i]==-1 || dfs(pre[i])){
pre[i]=s;
return 1;
}
}
}
return 0;
}
int main(){
int s,u,v;
int sum;
while(scanf("%d",&n)!=EOF && n){
scanf("%d %d",&m,&k);
memset(we,0,sizeof(we));
for(int i=0;i<k;i++){
scanf("%d %d %d",&s,&u,&v);
if(u>0 && v>0)//初始化为0所以0不用计算
we[u][v]=1;
}
sum=0;
memset(pre,-1,sizeof(pre));
for(int i=0;i<n;i++){
memset(vis,0,sizeof(vis));
if(dfs(i)){
sum++;
}
}
printf("%d\n",sum);
}
}