题目描述(ID:12100)
标题: Instrction Arrangement
标签:
详情: Ali has taken the Computer Organization and Architecture course this term. He learned that there may be dependence between instructions, like WAR (write after read), WAW, RAW.
If the distance between two instructions is less than the Safe Distance, it will result in hazard, which may cause wrong result. So we need to design special circuit to eliminate hazard. However the most simple way to solve this problem is to add bubbles (useless operation), which means wasting time to ensure that the distance between two instructions is not smaller than the Safe Distance.
The definition of the distance between two instructions is the difference between their beginning times.
Now we have many instructions, and we know the dependent relations and Safe Distances between instructions. We also have a very strong CPU with infinite number of cores, so you can run as many instructions as you want simultaneity, and the CPU is so fast that it just cost 1ns to finish any instruction.
Your job is to rearrange the instructions so that the CPU can finish all the instructions using minimum time.

https://acm.hdu.edu.cn/showproblem.php?pid=4109
有m个工程和N条生产线,每个生产线完成都需要一定的时间,每个工程开始的前提是连接它的生产线全部完成。可以多条生产线同时运作,求所有工程完成的最早时间(工程开始立即完成)。
给你一些指令,指令Y要在X发生后Z秒之后才能发生,问执行全部指令最少需要的时间。
输入格式:
The input consists several testcases.
The first line has two integers N, M (N <= 1000, M <= 10000), means that there are N instructions and M dependent relations.
The following M lines, each contains three integers X, Y , Z, means the Safe Distance between X and Y is Z, and Y should run after X. The instructions are numbered from 0 to N - 1.
输出格式:
Print one integer, the minimum time the CPU needs to run.
样例:

输入

5 2
1 2 1
3 4 1

输出

2

解释

In the 1st ns, instruction 0, 1 and 3 are executed;
In the 2nd ns, instruction 2 and 4 are executed.
So the answer should be 2.
登录并解答