#P1933. [NOI2010] 旅行路线

    ID: 881 远端评测题 3000~6000ms 125MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>动态规划,dp搜索2010NOI 系列O2优化剪枝插头 dp

[NOI2010] 旅行路线

Description

In 2010, the World Expo was held in Shanghai, China, attracting tens of millions of visitors from home and abroad. During the summer vacation, Xiao Z also came to the Shanghai Expo Park. She had heard that the Expo Park would be very crowded, and some pavilions might require queuing for several hours. She was fully prepared for that. To make her trip smoother and more enjoyable, Xiao Z decided to plan a detailed travel route before visiting.

Xiao Z collected a map of the Expo Park and found that, overall, the park is a very long and narrow area, and each pavilion occupies one square of almost the same size. Therefore, the entire park can be seen as an n×mn \times m matrix (n3n \leq 3), where each cell represents a themed pavilion.

Since different pavilions have different levels of popularity, the queueing times also differ. Based on statistics, Xiao Z marked each pavilion (x,y)(x, y) with Tx,y=0T_{x,y} = 0 or 11. If Tx,y=1T_{x,y} = 1, it means the pavilion is very popular and requires a long queue; if Tx,y=0T_{x,y} = 0, it means the pavilion is relatively ordinary and can be entered with almost no queue. Xiao Z wants to plan a reasonable route so that she alternates between popular and ordinary pavilions. This way, she will neither spend too long queueing at popular pavilions nor find the trip too dull by only visiting ordinary ones. Also, Xiao Z values efficiency: she hopes to visit all pavilions without taking unnecessary detours. Therefore, she wants the travel route to satisfy the following constraints:

  1. After visiting the pavilion at (x,y)(x, y), the next pavilion to visit is an adjacent and unvisited pavilion (x,y)(x^\prime, y^\prime), i.e., xx+yy=1|x - x^\prime| + |y - y^\prime| = 1.
  2. The starting point of the route lies on the boundary of the matrix, i.e., x=1x = 1 or x=nx = n or y=1y = 1 or y=my = m.

She prepares a 0/1 sequence LL of length n×mn \times m. She wants the ii-th visited pavilion (x,y)(x, y) to satisfy Tx,y=LiT_{x,y} = L_i.

Xiao Z wants to know how many different travel routes satisfy her requirements. Since the final answer can be large, she only wants the total number of feasible routes modulo 1119286911\,192\,869.

Input Format

  • The first line contains two positive integers n,mn, m.
  • Lines 22 to n+1n+1: each line contains mm 0/1 integers. In line i+1i+1, the jj-th number represents Ti,jT_{i,j}.
  • Line n+2n+2 contains n×mn \times m 0/1 integers, where the ii-th number represents LiL_i.

Output Format

Output a single integer: the total number of feasible travel routes modulo 1119286911\,192\,869.

2 2
1 0
0 1
1 0 1 0
4

Hint

Sample explanation:

The four feasible travel routes are:

$$\begin{aligned} (1,1) \to (1,2) \to (2,2) \to (2,1)\\ (1,1) \to (2,1) \to (2,2) \to (1,2)\\ (2,2) \to (1,2) \to (1,1) \to (2,1)\\ (2,2) \to (2,1) \to (1,1) \to (1,2) \end{aligned}$$

Constraints:

  • For 10%10\% of the testdata: n=1n = 1.
  • For 30%30\% of the testdata: n=2n = 2.
  • For 60%60\% of the testdata: n=3n = 3, and for 20%20\% of the testdata, all Ti,jT_{i,j} are 00.
  • For 100%100\% of the testdata: m50m \leq 50, Li,Ti,j=0L_i, T_{i,j} = 0 or 11.

Translated by ChatGPT 5