bzoj#P1955. [Wuhan2010] Assembling Services
[Wuhan2010] Assembling Services
注:原题面与数据不符。
题目描述
In this problem, you need to simulate the execution of service programs . Each program is described with sequence of integers: $T\ I\ in_1\ in_2 \ldots in_I\ O\ out_1\ out_2\ \ldots\ out_O$, that means it takes unit time to execute, needs input variables (i.e. ), and sets output variables (i.e. ) when it finishes running. A program can be started if and only if all these input variables are ready (initially available, or set by some other programs).
Imagine you have a super-computer which can execute as many programs in parallel as you like, and every variable can be read and written simultaneously by multiple programs. Your task is to calculate a particular "target" variable, as soon as possible.
Assume there are programs, shown in the table below:
Program No. | Time | Requires | Produces |
---|---|---|---|
The quickest time to get is , if only is available at startup.
You also need to construct an expression that shows how to execute the programs to achieve the minimal time. The grammar of the expression is recursive:
- Single Program:
Px
, where . (i.e.P2
,P499
, etc). Meaning: execute the program immediately. Then end of this program marks the end of this expression. - Execute in serial:
(S1S2...Sk)
, where everySi
is an expression. Note that the outermost pair of parentheses is mandatory. Meaning: execute expressionS1
, thenS2
immediately afterS1
ends, thenS3
immediately afterS2
ends, ..., and finallySk
immediately afterSk-1
ends. Then end of expressionSk
marks the end of the whole expression. - Execute in parallel:
(S1|S2|...|Sk)
, where everySi
is an expression. Note that the outermost pair of parentheses is mandatory. Meaning: execute expressionsS1
,S2
, ..., andSk
simultaneously. The end of last finished expression marks the end of the whole expression.
One of the possible expressions for the example above is (((P1P3)|P2)P4)
. (P1P2P3P4)
is not acceptable, since is available at time in that expression, later than the optimal time .
输入格式
Each case begins with three integers . The number of programs is , the number of variables is , and the target variable is . Variables are numbered to , programs are numbered to . The next line contains a 01 string of m characters. The -th character is if and only if the -th variable is initially available. The target variable is guaranteed to be unavailable at startup. The following lines describe the programs. Each line begins with an integer , the execution time, and an integer followed by integers , as stated above, then an integer followed by integers . The last test case is followed by , which should not be processed.
输出格式
For each test case, print the case number and the total time needed to get the target variable. If it's not possible to get the target variable, print instead.
If it's possible to get the target variable, print the expression after that, in the same line. Be sure to print a valid expression having at most characters, with each program printed at most once. There should be no whitespace characters within the expression.
To make this problem a little bit easier, it's allowed that some programs finish after the optimal time, as long as the target variable is available at the optimal time. You’re also allowed to print redundant parentheses (pay attention to the expression length, though). If such an expression does not exist, print "Can't do in serial-parallel.
", without quotes.
Print a blank line after the output of each test case.
4 5 5
10000
2 1 1 1 2
3 1 1 1 3
4 1 2 1 4
1 2 3 4 1 5
1 2 1
01
31 1 2 1 1
3 5 5
10100
3 1 1 1 2
1 1 3 1 4
3 2 4 2 1 5
1 3 3
100
1 1 1 1 2
0 0 0
Case 1: 7
Case 2: 31
Case 3: 6
Case 4: -1
样例解释 1
After a variable is set, it'll keep available forever. That's why P3
can be executed, in the third example.
Also note that there are some other correct expressions for the first sample, e.g. ((P1P3P4)|P2)
. You can even print (((P1P3)P4)|P2)
Or ((P1(P3P4))|P2)
. Any one of them is acceptable in this problem.
数据规模与约定
For all the test cases, , , , , .