#P8804. [蓝桥杯 2022 国 B] 故障

[蓝桥杯 2022 国 B] 故障

Problem Description

In software or system development, we may encounter many kinds of failures. To infer the cause from the observed symptoms, engineers summarize a 2D table called a correlation matrix to describe the relationship between failure causes and failure symptoms. For example:

Each row represents a failure cause, and each column represents a failure symptom. The matrix indicates that cause AA may produce symptoms 22, 33, 44, and cause BB may produce symptoms 11, 33.

In real development, if a failure cause occurs, engineers can compute the probability of each cause based on the observed symptoms, and then check the causes in descending order of probability, so as to locate the cause quickly.

Now assume that at any given time, only one failure cause can occur in the system, and for a given cause, the occurrences of different symptoms are independent events. For example:

Assume the system is currently affected by cause AA. There is a probability of 13\frac{1}{3} that symptom 22 occurs, a probability of 14\frac{1}{4} that symptom 33 occurs, and a probability of 12\frac{1}{2} that symptom 44 occurs. Since these 33 symptoms occur independently, the probability that symptoms 22, 33, and 44 occur at the same time is 12×3×4\frac{1}{2 \times 3 \times 4}.

By convention, if there is no x mark in the correlation matrix, it means this failure cause will definitely not produce that symptom. For example, cause AA will definitely not produce symptom 11. Based on historical experience testdata, we have obtained the probability of each failure cause occurring, as well as the probability of each symptom occurring under each failure cause.

Now, given the symptoms currently observed in the system, find the probability that each failure cause has occurred.

Input Format

Line 11: Two positive integers N,MN, M. NN is the number of failure causes (indexed 1N1 \ldots N), and MM is the number of failure symptoms (indexed 1M1 \ldots M).

Line 22: NN integers. The ii-th number is the probability PiP_{i} that failure cause ii occurs.

Lines 3N+23 \ldots N+2: Each line contains MM integers. The integer in row i+2i+2, column jj is PijP_{i j}, which represents the probability (percentage) that symptom jj occurs when failure cause ii occurs.

Line N+3N+3: One positive integer KK, the number of symptoms that are currently observed.

Line N+4N+4: KK positive integers, the indices of the currently observed symptoms in order, with no duplicates.

Output Format

Lines 1N1 \ldots N: Output each failure cause and its probability in descending order of probability. If probabilities are the same, output the smaller-indexed cause first. The first number is the cause index, and the second number is the failure probability (percentage), rounded to 22 decimal places.

3 5
30 20 50
0 50 33 25 0
30 0 35 0 0
0 0 0 25 60
1
3
2 56.89
1 43.11
3 0.00

Hint

For all test cases, $1 \leq N \leq 40, 1 \leq M \leq 20, 0 \leq P_{i} \leq 100, \sum\left(P_{i}\right)=100$, 0Pij1000 \leq P_{i j} \leq 100.

Lanqiao Cup 2022 National Contest B Group, Problem G.

Translated by ChatGPT 5