编程介的小学生 2017-08-28 10:28 采纳率: 20.5%
浏览 916
已采纳

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

  • 写回答

1条回答

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮