#P3774. 最优选择

最优选择

题目描述

小N手上有一个N*M的方格图,控制某一个点要付出Aij的代价,然后某个点如果被控制了,或者他周围的所有点(上下左右)都被控制了,那么他就算是被选择了的。一个点如果被选择了,那么可以得到Bij的回报,现在请你帮小N选一个最优的方案,使得回报-代价尽可能大。

输入格式

第一行两个正整数N,M表示方格图的长与宽。

接下来N行每行M个整数Aij表示控制的代价。

接下来N行每行M个整数Bij表示选择的回报。

输出格式

一个整数,表示最大的回报-代价(如果一个都不控制那么就是0)。

3 3
1 100 100
100 1 100
1 100 100
2 0 0
5 2 0
2 0 0
8

数据范围与约定

<span style="font-size:10.5pt;mso-bidi-font-size:11.0pt;<br />

font-family:宋体;mso-ascii-font-family:Calibri;mso-hansi-font-family:Calibri;

mso-bidi-font-family:"Times New Roman";mso-font-kerning:1.0pt;mso-ansi-language:

EN-US;mso-fareast-language:ZH-CN;mso-bidi-language:AR-SA">对于</span><span lang="EN-US" style="font-size:10.5pt;mso-bidi-font-size:11.0pt;font-family:Calibri;

mso-fareast-font-family:宋体;mso-bidi-font-family:"Times New Roman";mso-font-kerning:

1.0pt;mso-ansi-language:EN-US;mso-fareast-language:ZH-CN;mso-bidi-language:

AR-SA">100%</span><span style="font-size:10.5pt;mso-bidi-font-size:11.0pt;

font-family:宋体;mso-ascii-font-family:Calibri;mso-hansi-font-family:Calibri;

mso-bidi-font-family:"Times New Roman";mso-font-kerning:1.0pt;mso-ansi-language:

EN-US;mso-fareast-language:ZH-CN;mso-bidi-language:AR-SA">的数据,</span><span lang="EN-US" style="font-size:10.5pt;mso-bidi-font-size:11.0pt;font-family:Calibri;

mso-fareast-font-family:宋体;mso-bidi-font-family:"Times New Roman";mso-font-kerning:

1.0pt;mso-ansi-language:EN-US;mso-fareast-language:ZH-CN;mso-bidi-language:

AR-SA">N,M<=50</span><span style="font-size:10.5pt;mso-bidi-font-size:11.0pt;

font-family:宋体;mso-ascii-font-family:Calibri;mso-hansi-font-family:Calibri;

mso-bidi-font-family:"Times New Roman";mso-font-kerning:1.0pt;mso-ansi-language:

EN-US;mso-fareast-language:ZH-CN;mso-bidi-language:AR-SA">,</span><span lang="EN-US" style="font-size:10.5pt;mso-bidi-font-size:11.0pt;font-family:Calibri;

mso-fareast-font-family:宋体;mso-bidi-font-family:"Times New Roman";mso-font-kerning:

1.0pt;mso-ansi-language:EN-US;mso-fareast-language:ZH-CN;mso-bidi-language:

AR-SA">Aij,Bij</span><span style="font-size:10.5pt;mso-bidi-font-size:11.0pt;

font-family:宋体;mso-ascii-font-family:Calibri;mso-hansi-font-family:Calibri;

mso-bidi-font-family:"Times New Roman";mso-font-kerning:1.0pt;mso-ansi-language:

EN-US;mso-fareast-language:ZH-CN;mso-bidi-language:AR-SA">都是小于等于</span><span lang="EN-US" style="font-size:10.5pt;mso-bidi-font-size:11.0pt;font-family:Calibri;

mso-fareast-font-family:宋体;mso-bidi-font-family:"Times New Roman";mso-font-kerning:

1.0pt;mso-ansi-language:EN-US;mso-fareast-language:ZH-CN;mso-bidi-language:

AR-SA">100</span><span style="font-size:10.5pt;mso-bidi-font-size:11.0pt;

font-family:宋体;mso-ascii-font-family:Calibri;mso-hansi-font-family:Calibri;

mso-bidi-font-family:"Times New Roman";mso-font-kerning:1.0pt;mso-ansi-language:

EN-US;mso-fareast-language:ZH-CN;mso-bidi-language:AR-SA">的正整数。</span>