问题 E: Meadow

内存限制:512 MB 时间限制:5 S
题面:传统 评测方式:文本比较 上传者:
提交:1 通过:1

题目描述

There is A N×M size meadow. For each location (i,j)(1iN,1jM), if A(i,j)=1, it means that this location is planted with grass, and vice versa it means that this location is not planted with grass. If some location (i,j) is covered by a grass-covered(completely covered with grass) square area of size L×L, the energy of the meadow will increaseL×B(i,j) (the energy can be increased multiple times if a position covered by different square areas that meet the requirements).

You need to calculate the energy of the whole meadow.

输入格式

For the first line,input a positive integer T(1T5), representing the total number of test data.

For each test data, input two positive integers n and m (1n,m1000) in the first line, representing the size of the meadow.

The next n line, each m integer, input matrixA(0Ai,j1), representing whether there is planted with grass in this position.

The next n line, each m integer, input matrix B(0Bi,j105), representing the weight of each position.

输出格式

Output a line of a integer, representing the energy sum of the meadow, the answer may be large, need to modulus 109+7109+7.

"scanf" and "printf" are slower in this OJ and are not recommended for submission

输入样例 复制

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

输出样例 复制

94