luogu#P2413. yyy loves physics IV

yyy loves physics IV

Background

“Tremble, laboratory!”

yyy once again returned to that ravaged laboratory.

Problem Description

This time, the circuit that almost perished heroically in Round 1 has been brought out again. There are NN (1N261 \le N \le 26) components.

The physics ace yyy connected them with a bunch of wires—series, parallel, all kinds of combinations...

However, because yyy’s operation was too nonstandard, each component has a risk of being damaged. Using his genius brain, yyy calculated that the probability that component ii fails and becomes open is pip_i (0pi10 \le p_i \le 1). Because the circuit is too complex, yyy asks you to compute the probability that the entire circuit becomes open (disconnected).

Circuit wiring rules:

  • A single component is the smallest circuit, with A denoting component 1, B denoting component 2, and so on.
  • A series circuit composed of KK subcircuits is written as circuit 1, 2, ..., KK.
  • A parallel circuit composed of KK subcircuits is written as (circuit 1)(circuit 2)...(circuit KK).

Input Format

The first line contains an integer nn, the number of components.

The second line contains a string that describes the circuit.

The next nn lines each contain a real number pip_i, the probability that component ii becomes open.

Output Format

Output a real number: the probability that the entire circuit becomes open, accurate to 4 decimal places.

5                            
(A,B)((C)(D),E)
0.2
0.3
0.4
0.5
0.6
0.2992

Hint

Translated by ChatGPT 5