编程介的小学生 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条回答 默认 最新

报告相同问题?

悬赏问题

  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度