CF1447B.Numbers Box

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a rectangular grid with nn rows and mm columns. The cell located on the ii -th row from the top and the jj -th column from the left has a value aija_{ij} written in it.

You can perform the following operation any number of times (possibly zero):

  • Choose any two adjacent cells and multiply the values in them by 1-1 . Two cells are called adjacent if they share a side.

Note that you can use a cell more than once in different operations.

You are interested in XX , the sum of all the numbers in the grid.

What is the maximum XX you can achieve with these operations?

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt ( 1t1001 \le t \le 100 ). Description of the test cases follows.

The first line of each test case contains two integers nn , mm ( 2n2 \le n , m10m \le 10 ).

The following nn lines contain mm integers each, the jj -th element in the ii -th line is aija_{ij} ( 100aij100-100\leq a_{ij}\le 100 ).

输出格式

For each testcase, print one integer XX , the maximum possible sum of all the values in the grid after applying the operation as many times as you want.

输入输出样例

  • 输入#1

    2
    2 2
    -1 1
    1 1
    3 4
    0 -1 -2 -3
    -1 -2 -3 -4
    -2 -3 -4 -5

    输出#1

    2
    30

说明/提示

In the first test case, there will always be at least one 1-1 , so the answer is 22 .

In the second test case, we can use the operation six times to elements adjacent horizontally and get all numbers to be non-negative. So the answer is: 2×1+3×2+3×3+2×4+1×5=302\times 1 + 3\times2 + 3\times 3 + 2\times 4 + 1\times 5 = 30 .

首页