#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 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 , column , building a commercial district yields profit and building an industrial district yields profit . In addition, adjacent cells (two cells are adjacent if they share a common edge) of different types give extra profit: if cell has adjacent cells (obviously ) of a type different from , then this cell gains an extra profit of . Professor Tiger.S has surveyed the land, so the profit matrices 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 and , denoting the number of rows and columns of the region.
Lines to : each contains integers, the commercial-district profit matrix .
Lines to : each contains integers, the industrial-district profit matrix .
Lines to : each contains integers, the adjacent-extra-profit matrix .
It is guaranteed that , and .
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