Machine Schedule Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12621 Accepted: 5399
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
Source
Beijing 2002#include#include int const MAX = 105; bool g[MAX][MAX]; int cx[MAX], cy[MAX]; bool vis[MAX]; int n, m, k; int DFS(int x) { for(int y = 0; y < m; y++) { if(!vis[y] && g[x][y]) { vis[y] = true; if(cy[y] == -1 || DFS(cy[y])) { cx[x] = y; cy[y] = x; return 1; } } } return 0; } int MaxMatch() { int res = 0; memset(cx, -1, sizeof(cx)); memset(cy, -1, sizeof(cy)); for(int i = 0; i < n; i++) { if(cx[i] == -1) { memset(vis, false, sizeof(vis)); res += DFS(i); } } return res; } int main() { while(scanf("%d", &n) != EOF && n) { memset(g, false, sizeof(g)); scanf("%d %d", &m, &k); for(int i = 0; i < k; i++) { int tmp, x, y; scanf("%d %d %d", &tmp, &x, &y); if(x * y) g[x][y] = true; } int ans = MaxMatch(); printf("%d\n", ans); } }