#P6883. [COCI 2016/2017 #3] Kroničan

    ID: 7304 远端评测题 2000ms 32MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>动态规划 DP2016位运算COCI(克罗地亚)

[COCI 2016/2017 #3] Kroničan

Problem Description

Mislav has NN glass cups, numbered from 11 to NN. Each cup contains some water. You need to make it so that only KK cups contain water by pouring water (pouring the water from one cup into another).

It is known that pouring the water from cup ii into cup jj costs Ci,jC_{i,j}. Mislav wants to know the minimum total cost needed so that after pouring, only KK (or fewer) cups contain water.

Input Format

The first line contains two positive integers, N,KN, K.

The next NN lines each contain NN non-negative integers Ci,jC_{i,j}. The number in row ii, column jj means the cost to pour water from cup ii to cup jj. It is guaranteed that Ci,iC_{i,i} is always 00.

Output Format

Output the minimum total cost Mislav needs to pay to achieve the goal.

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

Hint

Explanation for Sample 1

Mislav does not need to pour any water. The total cost is 00.

Explanation for Sample 2

Mislav needs to pour the water from any one cup into any other cup, so that only two cups contain water. The total cost is 11.

Explanation for Sample 3

Mislav can pour water from cup 44 into cup 33, then pour the water in cup 33 into cup 55, and finally pour the water in cup 11 into cup 55. The total cost is 1+2+2=51+2+2=5.

Constraints

For 40%40\% of the testdata, N10N \le 10.

For 100%100\% of the testdata, 1KN20,Ci,j1051 \le K \le N \le 20, C_{i,j} \le 10^5.

Notes

Translated from COCI2016-2017 CONTEST #3 T3 Kroničan

Translated by ChatGPT 5