ACM computer factory
Time limit:1000 ms |
|
Memory limit:65536 K |
Total submissions:5412 |
|
Accepted:1863 |
|
Special Judge |
Description
As you know, all the computers used for ACM contests must be identical, so the participates in 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 usingNVarious 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 setPNumbers 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 setPNumbers 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 your 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 IntegersP n, ThenNDescriptions of the machines. The descriptionITh machine is represented as by 2P+ 1 IntegersQi Si, 1Si, 2...Si,P Di, 1Di, 2...Di,P, WhereQiSpecifies performance,Si,J-Input specification for PartJ,Di,K-Output specification for PartK.
Constraints
1 ≤P≤ 10, 1 ≤N≤ 50, 1 ≤Qi≤ 10000
Output
Output the maximum possible overall performance, thenM-Number of connections that must be made, thenMDescriptions of the connections. Each connection between machinesAAndBMust be described by three positive numbersA B W, WhereWIs the number of computers delivered fromAToBPer hour.
If several solutions exist, output any of them.
Sample Input
Sample input 13 415 0 0 0 0 1 010 0 0 0 0 1 130 0 1 2 1 1 13 0 2 1 1 1 1Sample input 23 55 0 0 0 0 1 0100 0 1 0 1 0 13 0 1 0 1 1 01 1 0 1 1 1 0300 1 1 2 1 1 1Sample input 32 2100 0 0 1 0200 0 1 1 1
Sample output
Sample output 125 21 3 152 3 10Sample output 24 51 3 33 5 31 2 12 4 14 5 1Sample output 30 0
Hint
Bold texts appearing in the sample sections are Ive ive and do not form part of the actual data.
Source
Northeastern Europe 2005, far-Eastern subregion: A computer consists of N parts. Now there are m machines, and each machine can combine one assembled computer into another. For example, (0, 1, 2) indicates that the first part is not completed, the second part is completed, and the third part can be completed or not. Then, the number of tasks that can be completed by M machines per unit time and the specific input and output statuses are given. Calculate the computer finished product output per unit time of the system and the transmission association between specific machines. Question: The question can be converted to the largest stream. The output status of one machine can be associated with the input status of another machine, as long as their status is "equals ", set a super source and sink, and then use dinic to solve the problem.
# Include <stdio. h> # include <string. h> # define maxn 55 # define INF 0x3fffffffstruct node {int in [10], out [10]; // split the int Q; // capacity} m [maxn]; int G [maxn <1] [maxn <1], que [maxn <1], M, N, MP; int G0 [maxn <1] [maxn <1], deep [maxn <1], vis [maxn <1]; bool equals (int A [], int B []) {for (int K = 0; k <n; ++ K) {if (a [k]! = 2 & B [k]! = 2 & A [k]! = B [k]) return false;} return true;} bool countlayer () {int I, id = 0, now, front = 0; memset (deep, 0, sizeof (deep); Deep [0] = 1; que [ID ++] = 0; while (front <ID) {now = que [Front ++]; for (I = 0; I <= mp; ++ I) if (G [now] [I] &! Deep [I]) {deep [I] = deep [now] + 1; if (I = Mp) return true; que [ID ++] = I ;}} return false;} int dinic () {int I, id = 0, maxflow = 0, mincut, POs, U, V, now; while (countlayer ()) {memset (VIS, 0, sizeof (VIS); vis [0] = 1; que [ID ++] = 0; while (ID) {now = que [ID-1]; If (now = Mp) {mincut = inf; for (I = 1; I <ID; ++ I) {u = que [I-1]; V = que [I]; If (G [u] [v] <mincut) {mincut = G [u] [v]; pos = u ;}} Maxflow + = mincut; for (I = 1; I <ID; ++ I) {u = que [I-1]; V = que [I]; G [u] [v]-= mincut; G [v] [u] + = mincut;} while (ID & que [ID-1]! = POS) vis [que [-- id] = 0;} else {for (I = 0; I <= mp; ++ I) {If (G [now] [I] & deep [now] + 1 = deep [I] &! Vis [I]) {que [ID ++] = I; vis [I] = 1; break ;}} if (I> MP) -- id ;}}} return maxflow;} int main () {// freopen ("stdin.txt", "r", stdin); int I, j, sum, count; while (scanf ("% d", & N, & M) = 2) {memset (G, 0, sizeof (g); for (I = 1; I <= m; ++ I) {scanf ("% d", & M [I]. q); For (j = 0; j <n; ++ J) scanf ("% d", & M [I]. in [J]); For (j = 0; j <n; ++ J) scanf ("% d", & M [I]. out [J]); G [I] [I + M] = m [I]. Q ;}// connection Exit and Entry For (I = 1; I <= m; ++ I) {for (j = I + 1; j <= m; ++ J) {If (equals (M [I]. out, M [J]. in) g [I + M] [J] = inf; If (equals (M [J]. out, M [I]. in) g [J + M] [I] = inf ;}// set super source and super sink for (I = 1; I <= m; ++ I) {// source point G [0] [I] = inf; For (j = 0; j <n; ++ J) if (M [I]. in [J] = 1) {G [0] [I] = 0; break ;}} MP = m <1 | 1; for (I = 1; I <= m; ++ I) {// sink point G [I + M] [MP] = inf; For (j = 0; j <n; ++ J) if (M [I]. out [J]! = 1) {G [I + M] [MP] = 0; break ;}// back up the source memcpy (G0, G, sizeof (g )); sum = dinic (); Count = 0; // determine which paths have streams passed through for (I = m + 1; I <MP; ++ I) for (j = 1; j <= m; ++ J) if (G0 [I] [J]> G [I] [J]) + + count; printf ("% d \ n", sum, count); // output the relationship between machines if (count) for (I = m + 1; I <MP; ++ I) for (j = 1; j <= m; ++ J) if (G0 [I] [J]> G [I] [J]) printf ("% d \ n", I-m, J, G0 [I] [J]-G [I] [J]);} return 0 ;}
Poj3436 ACM computer factory [maximum stream]