2014
11-29

# Crystal mine

Legends always begin with the sentence “Long long ago……”
Long long ago, there is a kingdom. The border of this kingdom is rectangular, and some lakes in it. Old king divides land to N * M areas. So, we can regard this kingdom as a matrix. Every element of matrix is an area. This kingdom is famous for crystal mine, because every land contains an ocean of crystal underground, except lakes.
Now, the old king wants to build a large rectangular mine field in a rectangular range which is decide by him. What’s more, he wants to build a special area in mine field, which can produce crystal manyfold. Notice that mine field can’t contain lakes. Unfortunately, the old king is too old to remember something. He always asks his adviser this question with different range.
Adviser is tired of answering those questions day by day. So, you are assigned to solve this problem. You get the kingdom map, and the amount of crystal of every area (as A[][]) has been marked on this map. You should find out the best plan to build this mine field which can produce most crystal. Old king never care the details of plan. The only thing he wants know is the number of crystal the mine field can produce.

There are several test cases in the input file.
The first line of input file contains a number T, representing the number of test cases. For each test case:
First line contains four integers separated by a single blank, N (1 <= N <= 150), M (1 <= M <= 150), Q (1<= Q <= 200), S (1 <= S <= 10). The size of matrix is N * M. Q indicates the number of questions of old king. S indicates that, if you set the special area in (i,j), (i,j) will produce S * A[i][j] instead of A[i][j].
The following N lines, each line contains M number, the j-th number of i-th line represent A[i][j] (-1 <= A[i][j] < 100 ). Number -1 indicates that, this area is a lake. Otherwise A[i][j] indicates the amount of crystal in this area.
Following Q line, each line contains four integers p, q, x, y. (1 <= p <= x <= N, 1 <= q <= y <= M) indicating the rectangular range of this question is from (p,q) to (x,y). (p,q) is upper left corner of range, and (x,y) is lower right corner of range.

There are several test cases in the input file.
The first line of input file contains a number T, representing the number of test cases. For each test case:
First line contains four integers separated by a single blank, N (1 <= N <= 150), M (1 <= M <= 150), Q (1<= Q <= 200), S (1 <= S <= 10). The size of matrix is N * M. Q indicates the number of questions of old king. S indicates that, if you set the special area in (i,j), (i,j) will produce S * A[i][j] instead of A[i][j].
The following N lines, each line contains M number, the j-th number of i-th line represent A[i][j] (-1 <= A[i][j] < 100 ). Number -1 indicates that, this area is a lake. Otherwise A[i][j] indicates the amount of crystal in this area.
Following Q line, each line contains four integers p, q, x, y. (1 <= p <= x <= N, 1 <= q <= y <= M) indicating the rectangular range of this question is from (p,q) to (x,y). (p,q) is upper left corner of range, and (x,y) is lower right corner of range.

1
4 4 3 2
1 -1 0 3
1 1 2 0
2 1 0 -1
1 4 6 1
1 1 1 1
1 1 3 3
1 3 3 4

Case 1:
2
9
8

1. Excellent Web-site! I required to ask if I might webpages and use a component of the net web website and use a number of factors for just about any faculty process. Please notify me through email regardless of whether that would be excellent. Many thanks

2. 第二块代码if(it != mp.end())应改为if(it != mp.end() && (i+1)!=(it->second +1))；因为第二种解法如果数组有重复元素 就不正确