问题 B: Assignment

内存限制:512 MB 时间限制:2 S
题面:传统 评测方式:文本比较 上传者:
提交:1 通过:1

题目描述

You are given two sequences �,�a,b of length n and a cost matrix A of size �×�n×nThe matrix A satisfies ��,�≥��,�−1Ai,jAi,j1 for all 1≤�≤�,1<�≤�1in,1<jn. You can do the following operation arbitrary number of times:

  • Select three integers �,�,�l,r,x satisfying 1≤�≤�≤�1lrn and 1≤�≤�1xn, then assign x to ��ai for all indices i between l and r, inclusive. The cost of this operation is ��,�−�+1Ax,rl+1.

For all �∈[0,�]i[0,k], find the minimum sum of costs to make a has at most i positions differing from b.

输入格式

The first line contains a single integer T (1≤�≤101T10), denoting the number of test cases.

For each test case, the first line contains two integers �,�n,k (1≤�≤1001n1001≤�≤101k10).

The second line contains n integers �1,�2,⋯,��a1,a2,,an (1≤��≤�1ain), denoting the sequence a.

The third line contains n integers �1,�2,⋯,��b1,b2,,bn (1≤��≤�1bin), denoting the sequence b.

The next n lines, each contains n integers. The j-th integer in the i-th line denotes ��,�Ai,j (1≤��,�≤1061Ai,j106).

It is guaranteed that for all 1≤�≤�1in1<�≤�1<jn��,�≥��,�−1Ai,jAi,j1.

输出格式

For each test case, output one line with �+1k+1 integers denoting the answer.

输入样例 复制

1
5 2
1 5 3 2 2
2 4 5 4 2
3 3 3 4 4
2 2 3 4 5
3 4 5 6 7
1 1 1 2 4
4 5 5 5 5

输出样例 复制

7 3 1