Under construction

Still being built. Things may change

Choosing Malatang Ingredients

Interview

Time limit1sMemory limit1024 MB

Summary
Given an N by N compatibility matrix, find the largest sum of pairwise scores over exactly K chosen ingredients.
Level

Easy3 of 10

Topics
Brute force, Bit manipulation
Solved
No attempts yet

Problem

Hayak likes putting several ingredients into malatang. Adding many ingredients does not always make it tastier, though. Each pair of ingredients has a compatibility score, so some combinations taste good together and others do not. Hayak is stuck on this problem.

How can Hayak maximize the flavor of malatang when using exactly KK ingredients?

Let Ci,jC_{i,j} be the compatibility of ingredient ii and ingredient jj when they are put in together. The flavor of the malatang is the sum of the compatibility scores over every pair of ingredients in the pot. If GG is the chosen group of ingredients, the flavor is:

∑i,j∈G, i<jCi,j\sum_{i, j\in G,\ i < j}C_{i,j}

For Hayak, find the maximum flavor when exactly KK ingredients are used.

Input

The first line contains two integers NN (1≤N≤101 \leq N \leq 10) and KK (1≤K≤N1 \leq K \leq N), separated by a space. The number of ingredients is NN, and KK is the number of ingredients to choose.

The next NN lines describe the compatibility scores. Line i+1i+1 contains the sequence Ci,1,Ci,2,…,Ci,NC_{i,1}, C_{i,2}, \ldots, C_{i,N} of integers, separated by spaces. (−1000≤Ci,j≤1000-1000 \leq C_{i,j} \leq 1000) It is given that Ci,i=0C_{i,i} = 0 and Ci,j=Cj,iC_{i,j} = C_{j,i}.

Output

Print one line with the maximum flavor of malatang when exactly KK ingredients are used.

Examples2

  1. Example 1

    Input
    4 3
    0 1 2 3
    1 0 -2 6
    2 -2 0 5
    3 6 5 0
    
    Expected output
    10
    
  2. Example 2

    Input
    4 1
    0 1 2 3
    1 0 -2 6
    2 -2 0 5
    3 6 5 0
    
    Expected output
    0