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

    报告相同问题?

    悬赏问题

    • ¥15 Arcgis相交分析无法绘制一个或多个图形
    • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
    • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
    • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
    • ¥30 3天&7天&&15天&销量如何统计同一行
    • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
    • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
    • ¥15 vs2019中数据导出问题
    • ¥20 云服务Linux系统TCP-MSS值修改?
    • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)