#graph1002. 圈地计划

圈地计划

Land Enclosure Plan

Problem Source

BZOJ 2132

Problem Description

Recently the real-estate company GDOI (Group of Dumbbells Or Idiots) obtained a plot of land for development from NOI (Nuts Old Idiots). The land is a rectangular region that can be divided into N×MN \times M small cells. GDOI wants to divide these cells into a commercial district and an industrial district for development. Depending on the terrain, building a commercial district or an industrial district in each cell yields different economic value. More specifically, for the cell in row ii, column jj, building a commercial district yields profit Ai,jA_{i,j} and building an industrial district yields profit Bi,jB_{i,j}. In addition, adjacent cells (two cells are adjacent if they share a common edge) of different types give extra profit: if cell (i,j)(i, j) has kk adjacent cells (obviously k≤4k \leq 4) of a type different from (i,j)(i, j), then this cell gains an extra profit of k×Ci,jk \times C_{i,j}. Professor Tiger.S has surveyed the land, so the profit matrices A,B,CA, B, C are already known. Can you help GDOI find a plan that maximizes the total profit?

Input Format

The first line contains two integers, the positive integers NN and MM, denoting the number of rows and columns of the region.

Lines 22 to N+1N+1: each contains MM integers, the commercial-district profit matrix AA.

Lines N+2N+2 to 2N+12N+1: each contains MM integers, the industrial-district profit matrix BB.

Lines 2N+22N+2 to 3N+13N+1: each contains MM integers, the adjacent-extra-profit matrix CC.

It is guaranteed that N,M≤100N, M \leq 100, and 0≤Ai,j,Bi,j,Ci,j≤1030 \leq A_{i,j}, B_{i,j}, C_{i,j} \leq 10^3.

Output Format

Output a single line containing one integer: the maximum profit.

Sample Input

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

Sample Output

81

Constraints

  • N,M≤100N, M \leq 100
  • 0≤Ai,j,Bi,j,Ci,j≤1030 \leq A_{i,j}, B_{i,j}, C_{i,j} \leq 10^3