QOJ.ac

QOJ

时间限制: 2 s 内存限制: 256 MB 总分: 100

#560. Tunnel

统计

Background

JSOI is a kingdom with a highly developed transportation network. Recently, to prevent sabotage by enemy spies, King JS has ordered the Minister of Transportation, JYY, to inspect the resilience of an underground tunnel system.

Description

The underground tunnel system of JSOI consists of $R$ rows and $C$ columns of key nodes. The rows and columns are numbered from $0$ to $R-1$ and $0$ to $C-1$, respectively. The key nodes in the leftmost column (column $0$) and the rightmost column (column $C-1$) are the surface entrances and exits of the tunnel system. The tunnel system is connected by horizontal and vertical unit-length tunnels, forming a grid graph. The figure below shows a $3 \times 4$ underground tunnel system.

Based on precise estimates from the intelligence department, each underground tunnel has a probability $p$ of being destroyed. The destruction of each tunnel is an independent event.

Given this underground network, JYY needs to calculate the probability that the tunnel system remains operational after enemy sabotage. The tunnel system is operational if and only if there exists a path of non-destroyed tunnels that allows travel from any surface entrance in column $0$ to any surface exit in column $C-1$.

Input

The first line contains two integers $R$ and $C$.

The next $R$ lines each contain $C-1$ integers. The $j$-th integer in the $i$-th line represents the probability (as a percentage) that the tunnel to the right of node $(i-1, j-1)$ is destroyed.

The next $R-1$ lines each contain $C-2$ integers. The $j$-th integer in the $i$-th line represents the probability (as a percentage) that the tunnel below node $(i-1, j)$ is destroyed.

Output

Output a single integer representing the probability that all key nodes remain connected. To avoid complex floating-point operations, assume the simplest fractional representation of the final answer is $\frac{p}{q}$. You only need to output the value of $(p \cdot q^{-1}) \pmod{10^9 + 7}$. Here, $q^{-1}$ is the smallest positive integer such that $(q \cdot q^{-1}) \pmod{10^9 + 7} = 1$.

Examples

Input 1

2 3
50 50
50 50
50

Output 1

500000004

Input 2

6 7
73 18 90 15 56 70
88 37 19 1 65 62
83 77 75 48 48 50
31 76 91 25 34 45
65 9 60 9 38 46
51 74 92 67 74 48
81 60 93 38 97
35 38 95 93 52
6 73 96 18 92
11 79 31 34 56
27 70 5 44 13

Output 2

701609622

Constraints

For $30\%$ of the data, $R, C \le 4$. For $50\%$ of the data, $R \le 8$. For $100\%$ of the data, $1 \le R \times C < 110$, $1 \le p \le 99$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.