编程介的小学生 2017-09-28 11:44 采纳率: 20.5%
浏览 831
已采纳

Lines

Problem Description
You play a game with your friend. He draws several lines on the paper with n×m square grids (see the left figure). After that, he writes down the number of lines passing through every integer coordinate in a matrix (see the right figure).

The number of lines passing though coordinate (i,j) is written in cell (i,j) in the right figure.(i,j both start from 0).

You are given the matrix written by your friend. You need to figure out the possible minimal number of lines your friend drew on the paper.

Input
The first line of the input contains an integer T indicating the number of test cases( 0 < T <= 10).

For each test case, the first line contains two integers n, m (1 ≤ n, m ≤ 50) representing the size of the grids on the paper. The following (n+1) × (m+1) numbers is what your friend writes. It is guaranteed that the number of lines your friend draws does not exceed 14. Each line passes through integer coordinates at least three times.

Output
For each test case, you need to output the minimal number of lines your friend drew on the paper in a single line.

Sample Input
1
5 4
0 1 0 0 1
0 1 0 1 0
2 1 1 0 0
0 3 1 0 0
1 1 1 0 1
0 1 0 1 0

Sample Output
4

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-10-16 02:15
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器