描述
传送门:poj-3436
As you know, all the computers used for ACM contests must be identical, so the participants compete on equal terms. That is why all these computers are historically produced at the same factory.
Every ACM computer consists of P parts. When all these parts are present, the computer is ready and can be shipped to one of the numerous ACM contests.
Computer manufacturing is fully automated by using N various machines. Each machine removes some parts from a half-finished computer and adds some new parts (removing of parts is sometimes necessary as the parts cannot be added to a computer in arbitrary order). Each machine is described by its performance (measured in computers per hour), input and output specification.
Input specification describes which parts must be present in a half-finished computer for the machine to be able to operate on it. The specification is a set of P numbers 0, 1 or 2 (one number for each part), where 0 means that corresponding part must not be present, 1 — the part is required, 2 — presence of the part doesn’t matter.
Output specification describes the result of the operation, and is a set of P numbers 0 or 1, where 0 means that the part is absent, 1 — the part is present.
The machines are connected by very fast production lines so that delivery time is negligibly small compared to production time.
After many years of operation the overall performance of the ACM Computer Factory became insufficient for satisfying the growing contest needs. That is why ACM directorate decided to upgrade the factory.
As different machines were installed in different time periods, they were often not optimally connected to the existing factory machines. It was noted that the easiest way to upgrade the factory is to rearrange production lines. ACM directorate decided to entrust you with solving this problem.
Input
Input file contains integers $P\ N$, then $N$ descriptions of the machines. The description of ith machine is represented as by $2 P + 1$ integers $Q_i\ S_{i,1}\ S_{i,2}\ …\ S_{i,P}\ D_{i,1}\ D_{i,2}\ …D_{i,P}$, where $Q_i$ specifies performance, $S_{i,j}$ — input specification for part $j, D_{i,k}$ — output specification for part $k$.
Constraints
$1\ ≤\ P\ ≤\ 10,\ 1\ ≤\ N\ ≤\ 50,\ 1\ ≤\ Q_i\ ≤\ 10000$
Output
Output the maximum possible overall performance, then $M$ — number of connections that must be made, then $M$ descriptions of the connections. Each connection between machines $A$ and $B$ must be described by three positive numbers $A\ B\ W$, where $W$ is the number of computers delivered from $A$ to $B$ per hour.
If several solutions exist, output any of them.
Examples
intput
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17Sample input 1
3 4
15 0 0 0 0 1 0
10 0 0 0 0 1 1
30 0 1 2 1 1 1
3 0 2 1 1 1 1
Sample input 2
3 5
5 0 0 0 0 1 0
100 0 1 0 1 0 1
3 0 1 0 1 1 0
1 1 0 1 1 1 0
300 1 1 2 1 1 1
Sample input 3
2 2
100 0 0 1 0
200 0 1 1 1output
1
2
3
4
5
6
7
8
9
10
11
12
13Sample output 1
25 2
1 3 15
2 3 10
Sample output 2
4 5
1 3 3
3 5 3
1 2 1
2 4 1
4 5 1
Sample output 3
0 0
大致题意
要生产一种产品,产品有P种零件,共有N台机器,输入的每一行第一个数字代表这台机器的产量,2-1+P个数字表示这个机器能处理的半成品状态,1表示需要这个零件,0表示不需要这个零件,2表示这个零件可有可无。 后P个表示这个机器产出的产品状态,1表示有这个零件,0表示没有零件。
求组装好的成产线的最大工作效率(每小时最多生成多少成品,成品的定义就是所有部分的状态都是”1”)
思路
- 如果一个机器的产出和另一个机器的需求一样的话,就可以连一条边,如果一个机器输入的的零件没有1的话,就和s连一条边,如果输出全为1(即成品),就与t连一条边。跑最大流。
- 由于每个机器输出是有限的,所以还是一样通过拆点来加以限制,对于每个机器 i都拆成 i,i’两个节点,再连一条权值为产量的边。
- 这道题需要记录路径,在跑完最大流之后,对所有边判断一下是否有流量。还要排除原本没有的点,比如链接到s和t的边、拆点之后i和i’之间的边。
代码
1 |
|