2019-02-09 17:10 阅读 800


Problem Description
As a cheap labor in a small company, LL has to ride back and forth between school and office every day. It is a tedious trip. So he want to design the most satisfactory riding route. After several day's experiment, he draw the simple map. It contains n*m areas. The school is in (0,0) while the office is in (n-1,m-1). He also record the scenery rank of each area A(i,j) and the time need to ride through each area B(i,j). ( For the start and end, A(0,0), B(0,0), A(n-1,m-1), B(n-1,m-1) are always 0. ) Now, LL defines the satisfactory degree of a round trip as follow:

                                   ∑{ A(i,j) | Area (i,j) is in the riding route (come or go). }

the satisfactory degree = ----------------------------------------------------------------------
∑{ B(i,j) | Area (i,j) is in the riding route (come or go). }

Attention: 1. LL doesn't want to make a detour. So, from school to office he only ride rightward or downward and from office to school only leftward or upward.
2. LL won't pass the same area in the whole round trip except the start and end.

Each test case begins with two integers n,m ( 3<=n,m<=30 ), which is the size of the map. Then n lines follow, each contains m integers A(i,j). Another n lines follow, each contains m integers B(i,j). 1 <= A(i,j),B(i,j) <= 100.

For each case, Output the maximal satisfactory degree he can get in a round trip.

Sample Input
3 3
0 1 2
3 4 5
6 7 0
0 7 6
5 4 3
2 1 0

Sample Output

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享