CF1366C.Palindromic Paths

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

You are given a matrix with nn rows (numbered from 11 to nn ) and mm columns (numbered from 11 to mm ). A number ai,ja_{i, j} is written in the cell belonging to the ii -th row and the jj -th column, each number is either 00 or 11 .

A chip is initially in the cell (1,1)(1, 1) , and it will be moved to the cell (n,m)(n, m) . During each move, it either moves to the next cell in the current row, or in the current column (if the current cell is (x,y)(x, y) , then after the move it can be either (x+1,y)(x + 1, y) or (x,y+1)(x, y + 1) ). The chip cannot leave the matrix.

Consider each path of the chip from (1,1)(1, 1) to (n,m)(n, m) . A path is called palindromic if the number in the first cell is equal to the number in the last cell, the number in the second cell is equal to the number in the second-to-last cell, and so on.

Your goal is to change the values in the minimum number of cells so that every path is palindromic.

输入格式

The first line contains one integer tt ( 1t2001 \le t \le 200 ) — the number of test cases.

The first line of each test case contains two integers nn and mm ( 2n,m302 \le n, m \le 30 ) — the dimensions of the matrix.

Then nn lines follow, the ii -th line contains mm integers ai,1a_{i, 1} , ai,2a_{i, 2} , ..., ai,ma_{i, m} ( 0ai,j10 \le a_{i, j} \le 1 ).

输出格式

For each test case, print one integer — the minimum number of cells you have to change so that every path in the matrix is palindromic.

输入输出样例

  • 输入#1

    4
    2 2
    1 1
    0 1
    2 3
    1 1 0
    1 0 0
    3 7
    1 0 1 1 1 1 1
    0 0 0 0 0 0 0
    1 1 1 1 1 0 1
    3 5
    1 0 1 0 0
    1 1 1 1 0
    0 0 1 0 0

    输出#1

    0
    3
    4
    4

说明/提示

The resulting matrices in the first three test cases:

(1101)\begin{pmatrix} 1 & 1\\ 0 & 1 \end{pmatrix} (000000)\begin{pmatrix} 0 & 0 & 0\\ 0 & 0 & 0 \end{pmatrix} (101111101101101111101)\begin{pmatrix} 1 & 0 & 1 & 1 & 1 & 1 & 1\\ 0 & 1 & 1 & 0 & 1 & 1 & 0\\ 1 & 1 & 1 & 1 & 1 & 0 & 1 \end{pmatrix}

首页