编程介的小学生 2017-11-08 02:42 采纳率: 20.5%
浏览 326
已结题

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 sub-matrix'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 4190

Sample Output
9994
14313

  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥30 这是哪个作者做的宝宝起名网站
    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!