POJ 1325 && ZOJ 1364--machine Schedule "Two-point diagram && Minimum point cover number "

Source: Internet
Author: User

Machine Schedule
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 13071 Accepted: 5575

Description

As we all know, machine scheduling are a very classical problem in computer science and have been studied for a very long hi Story. 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 was machines a and B. Machine A have n kinds of working modes, which is called Mode_0, Mode_1, ..., mode_n-1, lik Ewise machine B has m kinds of working modes, MODE_0, Mode_1, ..., mode_m-1. At the beginning they is both work at Mode_0.

For k jobs given, each of the them can is processed in either one of the one of the both machines in particular mode. For example, job 0 can either is processed in machine A at mode_3 or in machine B at Mode_4, Job 1 can either be processed In machine A is mode_2 or in machine B at Mode_4, and so on. Thus, for Job I, the constraint can is represent as a triple (I, X, y), which means it can be processed either 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 is 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 <) and K (K < 1000). The following k lines give the constrains of the K jobs, each of which is a triple:i, X, Y.

The input would be terminated to a line containing a single zero.

Output

The output should is 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
Test instructions

There is a A, b two machines. Machine A has n mode of operation, respectively mode_0,mode_1,mode_2 ...., machine B has m mode of operation, respectively, Mode_0,mode_1. Mode_2 ... Just started a. B's working mode is mode_0.

Given a K task. expressed as (i. X. y), meaning that the operation I can work in machine A's mode_x mode or machine B's mode_y mode.

In order to complete the work, the machine's working mode must be switched on and off from time to time, but the switching machine mode can only be done by restarting the machine, asking you to restart at least how many times. Ability to assign work to the end.


Analytical:

A look at A, B machines, and then according to test instructions, two machines have a matching relationship, we first construct a binary map, the n mode of a and B of the M mode as the vertex of the graph. Suppose a task can be completed on the mode_j of Mode_i or B of a. A side from Ai to BJ, which makes up a two-point chart.

By test instructions, it is expected that the minimum point covering set problem of the binary graph, that is, the smallest vertex set, "covering" all the edges, can be transformed into the maximum matching problem of the binary graph.

The minimum point coverage number of a binary graph = = maximum number of matches.

Also note that both machine A and machine B are initially mode_0. So for those who can work on machine A's mode_0 or machine B mode _0, there is no need to restart the machine at the end of these operations.

I didn't think about it at the beginning. Contributed a WA.


#include <cstdio> #include <cstring> #include <algorithm> #define MAXN 110using namespace Std;int map[        Maxn][maxn];int used[110];int link[maxn];int N, M, k;void Getmap () {while (k--) {int C, a, B;        scanf ("%d%d%d", &c, &a, &b);        if (a = = 0 | | b = = 0) continue;    MAP[A][B] = 1;            }}bool dfs (int x) {for (int i = 0; i < m; ++i) {if (!used[i] && map[x][i]) {used[i] = 1;                if (link[i] = = 1 | | DFS (LINK[I])) {link[i] = x;            return true; }}} return false;}    int Hungary () {int ans = 0;    memset (link, 1, sizeof);        for (int i = 0; i < n; ++i) {memset (used, 0, sizeof (used));    if (Dfs (i)) ans++; } return ans;        int main () {while (scanf ("%d", &n), N) {scanf ("%d%d", &m, &k);        memset (map, 0, sizeof (map));        Getmap ();        int sum = 0;        sum = Hungary (); printf ("%d\n", sum);   } return 0;} 


POJ 1325 &amp;&amp; ZOJ 1364--machine Schedule "Two-point diagram &amp;&amp; Minimum point cover number "

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.