1371. Printed-Circuit Boards

单点时限: 2.0 sec

内存限制: 256 MB

Write a program which:

reads the description of a series-parallel circuit,

computes the minimal number of connections that must run on the top side of the board,

writes the result.

输入格式

From the standard input one should read the description of a series-parallel circuit. The description is in a recursive form:

1.if the first line of the description contains a capital letter S and a positive integer n (2 <= n <= 10000) separated from each other by a single space, then the circuit being described consists of n smaller circuits connected in series; they are described in the successive lines,

2.if the first line of the description contains a capital letter R and a positive integer n (2 <= n <= 10000) separated from each other by a single space, then the circuit being described consists of n smaller circuits connected in parallel (by means of two branching units); they are described in the successive lines,

3.a line containing only one capital letter X describes a circuit consisting of a single unit only.

The total number of letters X occurring in the description of a circuit does not exceed 10000000, and the recursive depth of the description does not exceed 500.

输出格式

Your program should write to the standard output. In the first line there should be one integer equal to the minimal number of connections that must run on the top side of the board.

样例

Input
R 3
S 2
X
R 2
S 2
X
X
S 2
X
X
S 3
X
X
X
R 2
X
X
Output
8
hint:

0 人解决,1 人已尝试。

0 份提交通过,共有 3 份提交。

9.9 EMB 奖励。

创建: 16 年,11 月前.

修改: 6 年,10 月前.

最后提交: 3 年,7 月前.

来源: POI

题目标签