|
||||||||||
LinesTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1246 Accepted Submission(s): 375 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
Sample Output
Source | ||||||||||
|