shunfurh 于 2017.08.28 18:28 提问
 Life Game

Problem Description
Rich people are playing life game,generally it is like they find some poor people. And they brainwash those people,make them believe that they have to kill all other to live. And they watch the procedure and bet on the results for fun. Of course they will kill the winner when the winner believe that he wins.
Today's game is different from before.There is a n*m matrix of people. Now you are the organizer and you can control those people's life.
If people at row i, column j, survive at the end, you will be rewarded with wi,j money.Otherwise you are rewarded with bi,j money.
Also,those rich people have some strange request, each one will point out a contiguous sub matrix of this matrix and say: if people in this sub matrix all die(or survive), you are
rewarded with s money.
You don't really care about those people's life, so you want to maximize the money you get.
What is the maximum money you can get if you kill those people optimally?
Please note that there's no restriction on killing people, you can kill no one, you can also kill everyone.
(Following text is irrelevant with the problem)
In the end, you kill everybody, and you find that you have been brainwashed too, and those people you killed are actually your friends and family. Then you get crazy and kill yourself, and those rich people enjoy a lot.
And the true organizer, I, get all the money supposed to be yours :).Input
The first line contains an integer T(1<=T<=5).Denoting the number of the test cases.
For each test cases,the first line contains three integers n, m, r(n<=50, m<=50, r<=50000),denote the number of rows,the number of columns and the number requests.
Then follows a n * m integer matrix b.
Then follows a n * m integer matrix w.
0<=bi,j , wi,j<=100
Then r lines follows,each represent a request.
Each lines contains 6 integers r1, c1, r2, c2, t, s. It means the submatrix's top left corner is (r1, c1), and the bottom right corner is (r2, c2). t = 0 if they should survive, t = 1 if they should die. s is the reward you can get if this request are fulfilled. 0<=s<=10000.Output
For each test cases,print the answer in one line.Sample Input
2
2 2 3
34 44
63 30
1 9
53 57
1 2 2 2 1 2843
1 1 2 1 0 2169
2 1 2 1 1 6980
2 2 3
50 93
65 70
52 28
91 25
1 1 2 1 0 9862
2 1 2 1 1 1876
2 2 2 2 0 4190Sample Output
9994
14313