[The topic description is extremely confusing] job scheduling solution

Source: Internet
Author: User

[Description]

Now we need to use M machines to process N parts, each of which has m processes, each of which is completed on different designated machines. Each process of each workpiece has a specified processing time.
Each process of each workpiece is called an operation. We use the Mark J-K to represent an operation, where J is a number from 1 to n and is the workpiece number; K is a number ranging from 1 to M. It is a serial number. For example, 2-4 indicates the operation of 2nd processes for 4th workpieces. In this question, we also give an order for each operation.
For example, when n = 3, m = 2, "1---" is a given order, that is to say, first arrange 1st processes for 1st workpieces, then arrange 1st processes for 2nd workpieces, and then arrange 2nd processes for 1st workpieces.
On the one hand, each operation must meet the following two constraints.
(1) For the same workpiece, each process must be completed before it can begin;
(2) Each machine can process at most one workpiece at a time.
On the other hand, you cannot change the working status of the previously scheduled operation when you schedule subsequent operations.
Because the same workpiece is arranged in the order of the process, only the workpiece number is given in the original order, and the same order can still be obtained. Therefore, in the input data, we abbreviated the order as "1 1 2 3 3 2 ".
Note that the "arrangement order" only requires that each operation be arranged in the given order. Not necessarily the actual operation sequence on each machine. During the specific implementation, it is possible that an operation is completed first than the previous operation.
For example, n = 3, m = 2. The known data is as follows:
Workpiece number machine number/processing time
Process 1 PROCESS 2
1 1/3 2/2
2 1/2 2/5
3 2/2 1/4
The two implementation plans in the "1 1 2 3 3 2" order are correct. However, the total time required is 10 and 12 respectively.

When an operation is inserted to an empty file of a machine (the last part of the machine that has not been scheduled can also be regarded as a blank file), the operation can be inserted before, back or center. In order to make the problem simpler, we agree that we should try to insert it in front of the constraints (1) (2. In addition, we also agree that if there are multiple blank files that can be inserted, it will be inserted to the first blank file under the condition that the constraint condition (1) (2) is guaranteed. Therefore, under these conventions, solution 1 in the above example is correct, and solution 2 is incorrect.
Obviously, under these conventions, the implementation scheme that matches the given arrangement sequence is unique. Please calculate the total time required for the scheme to complete all tasks.

[Input format]

The 1st act of the input file is two positive integers separated by a space:
M n
(M (<20) indicates the number of machines, and N (<20) indicates the number of jobs)
Row 2nd: numbers separated by spaces, in the order given.
In the following 2n rows, each row is M positive integers separated by spaces, and each number cannot exceed 20.
The first n rows represent the number of machines used in each process of each workpiece in sequence. The number of machines in 1st is the number of machines in 1st processes, and the number of machines in 2nd is the number of machines in 2nd processes.
The next n rows represent the processing time of each process of each workpiece in sequence.
It can be ensured that all the above data is correct and does not need to be tested.

[Output format]

The output file has only one positive integer, which is the minimum processing time.

[Example input]

2 3
1 1 2 3 3 2
1 2
1 2
2 1
3 2
2 5
2 4
[Sample output]

10

[Analysis]

Use a bool array to simulate it.

 

# Include <stdio. h> bool use [20] [10000]; int ans, n, m, list [500]; int time [30] [30], me [30] [30], now [30], Max [30], last [30]; int main () {scanf ("% d", & M, & N ); for (INT I = 1; I <= m * n; ++ I) scanf ("% d", & list [I]); For (INT I = 1; I <= N; ++ I) for (Int J = 1; j <= m; ++ J) scanf ("% d ", & me [I] [J]); For (INT I = 1; I <= N; ++ I) for (Int J = 1; j <= m; ++ J) scanf ("% d", & time [I] [J]); For (INT I = 1; I <= m * n; ++ I) {int x = List [I]; ++ now [X]; int y = now [X]; for (Int J = last [x] + 1; j <10000; ++ J) if (! Use [me [x] [y] [J]) {int can = 1; for (int K = 1; k <= time [x] [Y]; ++ K) if (use [me [x] [Y] [J + k-1]) {can = 0; break;} If (CAN) {for (int K = 1; k <= time [x] [Y]; ++ K) use [me [x] [y] [J + k-1] = 1; if (J + time [x] [Y]-1> MAX [me [x] [Y]) max [me [x] [Y] = J + time [x] [Y]-1; last [x] = J + time [x] [Y]-1; break ;}}for (INT I = 1; I <= m; ++ I) if (MAX [I]> ans) ans = MAX [I]; printf ("% d \ n", ANS); Return 0 ;}

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.