#P1935. [国家集训队] 圈地计划

[国家集训队] 圈地计划

Description

Recently, the real estate developer GDOI (Group of Dumbbells Or Idiots) obtained a piece of land for development from NOI (Nuts Old Idiots). This land is a rectangular area that can be divided into N×MN \times M small cells. GDOI requires dividing these cells into a commercial zone and an industrial zone for development. Due to different terrain conditions, building a commercial zone or an industrial zone on each cell will yield different economic values. More specifically, for the cell in the ii-th row and jj-th column, building a commercial zone yields revenue Ai,jA_{i,j}, and building an industrial zone yields revenue Bi,jB_{i,j}. In addition, adjacent cells can bring extra revenue: if cell (i,j)(i,j) has kk neighboring cells (adjacency means two cells share a common side) whose type is different from that of (i,j)(i,j), then this cell gains an additional revenue of k×Ci,jk \times C_{i,j}. After Professor Tiger.S’s survey, the revenue matrices AA, BB, and CC are known. Can you help GDOI find a plan that maximizes the total revenue?

Input Format

The first line contains two integers, positive integers NN and MM, representing the number of rows and columns of the area, respectively.

Lines 22 to N+1N+1: each line contains MM integers, representing the commercial revenue matrix AA.

Lines N+2N+2 to 2N+12N+1: each line contains MM integers, representing the industrial revenue matrix BB.

Lines 2N+22N+2 to 3N+13N+1: each line contains MM integers, representing the extra revenue matrix CC for adjacent cells.

Output Format

Output a single line containing one integer, the maximum total revenue.

3 3
1 2 3
4 5 6
7 8 9
9 8 7
6 5 4
3 2 1
1 1 1
1 3 1
1 1 1
81

Hint

1N,M101 \leq N, M \leq 10, 0Ai,j,Bi,j,Ci,j1030 \leq A_{i,j}, B_{i,j}, C_{i,j} \leq 10^3.

Translated by ChatGPT 5