#P8983. 「DROI」Round 1 失控

    ID: 10010 远端评测题 800ms 128MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划 DP洛谷原创O2优化动态规划优化

「DROI」Round 1 失控

Background

Being out of control might actually be being rational.

Problem Description

You are given an n×mn \times m matrix GG and two permutations p,qp, q of length mm.

We say an element Gi,jG_{i,j} is out of control if and only if Gi,jGi1,pj>C\vert G_{i,j} - G_{i-1,p_j} \vert > C and Gi,jGi+1,qj>C\vert G_{i,j} - G_{i+1,q_j} \vert > C, where CC is a given constant. In particular, we define that no element in row 11 and row nn is out of control no matter what.

Then you are also given two sequences AA and BB, both of length kk.

You have kk types of operations. The ii-th operation adds AiA_i to all elements in a chosen row, and costs BiB_i. Each operation type can be used any number of times, but for each row, you may either apply exactly one of these operation types or do nothing. Also, you must ensure that among any two adjacent rows, at most one row is operated on.

Find the minimum total cost to make every element in matrix GG not out of control (the testdata guarantees that a solution exists).

Input Format

The first line contains four integers n,m,k,Cn, m, k, C.

The next n+4n + 4 lines are as follows: the first nn lines each contain mm numbers, describing matrix GG. Lines n+1n + 1 and n+2n + 2 each contain mm numbers, describing permutations pp and qq, respectively. The last two lines each contain kk numbers, describing sequences AA and BB, respectively.

Output Format

Output one integer in a single line, representing the answer.

3 3 5 10
1 2 6
7 3 11
9 44 5
2 3 1
1 3 2
5 10 15 20 25
6 6 6 6 6
0
8 8 8 28
49 11 44 31 25 37 41 1 
29 38 46 21 21 17 45 47 
1 37 11 31 8 15 15 47 
21 47 15 6 11 9 40 28 
21 29 1 11 39 15 21 35 
26 20 3 38 1 41 27 21 
41 41 31 16 11 1 24 3 
33 15 23 26 7 47 49 8 
3 8 2 4 6 5 1 7 
7 5 8 3 6 1 4 2 
36 13 12 3 38 49 22 55 
20 24 2 30 26 25 17 25 
32

Hint

Sample Explanation #1

Obviously, for sample 1, performing no operation is enough to ensure that all elements are not out of control.


Sample Explanation #2

Apply operation 33 on row 33, and apply operation 44 on row 77. It can be proven that there is no better solution.


Constraints

"This problem uses bundled subtasks."

  • Subtask1(10%)\operatorname{Subtask} 1(10\%): n,m,k8n, m, k \leq 8.

  • Subtask2(30%)\operatorname{Subtask} 2(30\%): m50,k100m \leq 50, k \leq 100.

  • Subtask3(20%)\operatorname{Subtask} 3(20\%): m50,k1000m \leq 50, k \leq 1000.

  • Subtask4(40%)\operatorname{Subtask} 4(40\%): no special restrictions.

For 100%100\% of the testdata: 3n503 \leq n \leq 50, 1m3001 \leq m \leq 300, 0k20000 \leq k \leq 2000, C,Gi,j,Ai,Bi106C, G_{i,j}, A_i, B_i \leq 10^6.

The input size is large. Please use a fast input method.


Hint

  • This problem is not strict about constant factors. If you feel your algorithm is just a bit too slow to pass the next Subtask, please do not get stuck optimizing meaningless constants, because that missing part may need a better algorithm to make up for it.

Translated by ChatGPT 5