1804: Doctor NiGONiGO’s multi-core CPU

内存限制:128 MB 时间限制:3.000 S
评测方式:文本比较 命题人:
提交:0 解决:0

题目描述

Doctor NiGONiGO has developed a new kind of multi-core CPU, it works as follow. There are q (1 < q ≤ 50) identical cores in the CPU, and there are p (0 < p ≤ 200) jobs need to be done. Each job should run in some core and need only one unit time. The cores in the CPU can work simultaneously but each core can implement only one job at a time. When a job completed, it will incur a deferral cost. Job i has a deferral cost c(i, j) (0 ≤ c(i, j) ≤ 1000000), where j is the completion time of the job (1 ≤ j ≤ p because any job done in the time later than p obviously not the optimal solution). Here we assume that c(i, j) is a monotonically no decreasing function of j. Now you are asked to find the schedule which have the minimum overall deferral cost.

输入

An integer T indicated the number of test cases. For each test case: There are two integers q, p in first line. And Following is p lines, each line contain p integer, the jth integer of the ith line is the deferral cost c(i, j).

输出

For each test case, output a singer integer, which is the minimum total deferral cost of the Problem.

样例输入 复制

1
2 4
89 145 181 269
4 86 158 164
60 143 157 165
4 45 109 207

样例输出 复制

254

提示

a. In the sample case, core 1 execute the job 2, 1 in sequence; core 2 execute the job 3, 4 in sequence, thus the optimal solution has the overall cost (4 + 145) + (60 + 45) = 254. b. Huge input.